日期:2014-05-16  浏览次数:20353 次

Struts2如何获取JSP页面数据,action 这样写问题出在哪里,请大家指教,能否把代码修改一下,谢谢
增加学生信息
public String addStudent()throws Exception{
System.out.println("增加学生开始*******************"+studentService);
try{
Student stu = new Student();
stu.setName(name);
stu.setSex(sex);
stu.setAge(age);
stu.setBirthday(birthday);
stu.setEmail(email);
stu.setHomeAddress(homeAddress);
studentService.addStudent(stu);
// HttpServletRequest request = ServletActionContext.getRequest();
// name = request.getParameter("name");
// sex = request.getParameter("sex");
// age = Integer.parseInt(request.getParameter("age"));
// DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
// birthday = format1.parse(request.getParameter("birthday"));
// email = request.getParameter("email");
// homeAddress = request.getParameter("homeAddress");
// Student s = new Student();
// s.setName("wangerxiao");
// s.setSex("W");
// s.setEmail("wangerxiao@163.com");
// student.setAge(20);
// student.setBirthday(new Date());
// s.setHomeAddress("响水县滨海路商业街");
// studentService.addStudent(s);
}catch(Exception ex){
ex.printStackTrace();
}
return SUCCESS;
}

JSP页面代码:
<s:form action="addStudent.action" id="addStudentForm" theme="simple"
name="addStudentForm" onsubmit="checkFroms();return false;">
<s:token/>
<table width="300"  border="0" align="left" cellspacing="1" class="table_1px_form tds">
<tbody>
<tr>
  <td align="center" colspan="2">
<span class="title">学生信息</span>
  </td>
</tr>
<tr>
          <td width="100" align="right">学生姓名 :</td>
   <td width="140" align="left">
<s:textfield name="student.name" id="studentName" theme="simple"/>
   </td>
</tr>
<tr>
           <td width="100" align="right">性别 :</td>
    <td width="140" align="left">
<s:textfield  name="student.sex" id="studentSex"></s:textfield>
    </td>
       </tr>
<tr>
    <td align="right">年龄 :</td>
    <td align="left">
<s:textfield  name="student.age" id="studentAge"></s:textfield>
    </td>
</tr>
<tr>
    <td align="right">出生日期:</td>
    <td align="left">
<s:textfield  name="student.birthday" id="studentBirthday"></s:textfield>
    </td>
</tr>

<tr>
     <td align="right">Email:</td>
     <td align="left">
<s:textfield  name="student.email" id="studentEmail"></s:textfield>
     </td>
</tr>
<tr>
     <td align="right">家庭地址:</td>
     <td align="left">
<s:textfield  name="student.homeAddress" id="studentHomeAddress"></s:textfield>
     </td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" id="button" name="button" value="新u22686 "/>
       </td>
</tr>
</tbody>
</table>
</s:form>