In the index.jsp
只需使用重定向到注册页面的代码
<% response.sendRedirect("registerAction.action"); %>
in the register.jsp
表单映射到registerAction
通过表格action
属性。动作映射应该是
<action name="registerAction" class="action.RegisterAction" >
<result name="success">register.jsp</result>
</action>
<action name="register" class="action.RegisterAction" method="register">
<result name="input">register.jsp</result>
<result name="success">login.jsp</result>
</action>
该映射更改为register
代码中使用的操作类的方法来插入一个新的与提供的一起使用的months
执行操作之前应填充的值。这input
result 用于 JSP 中表单标记的位置。这login.jsp
未知,但它将被用作register
行动。表格也应该重命名
<s:form action="register">
<s:select label="Select Date of Month" key="Month List" name="months" headerKey="0" headerValue="--Select--" list="allMonths" listKey="id" listValue="name"/>
<s:submit value="Register"/>
</s:form>
操作的代码发生变化
private String months;
//public getter and setter of months
public String register() throws Exception {
User u = new User();
u.setName(name);
u.setEmail(email);
u.setAddress(address);
u.setPhno(phno);
u.setPwd(pwd);
System.out.println(months);
u.setMonths(months);
udao.addUser(u);
return "success";
}
private List<Month> allMonths;
//public getter and setter of allMonths
假设动作类实现Preparable
,最好在这里立即执行此操作,因为如果验证(如果有)失败,可以使用该列表。
public void prepare() throws Exception {
//populate allMonths
//and set the value of months if you want it to be preselected.
}
并且该行动应延长ActionSupport
那些有execute
方法已经实现。