RegisterForm: /* * Created on 2006-3-6 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package app;import org.apache.struts.action.ActionForm;/** * @author kfzx-yancw * * TODO To change the template for this generated type comment go to Window - * Preferences - Java - Code Style - Code Templates */ public class RegisterForm extends ActionForm { protected String username; protected String password1; protected String password2; public String getUsername () {return this.username;}; public String getPassword1() {return this.password1;}; public String getPassword2() {return this.password2;}; public void setUsername (String username) {this.username = username;}; public void setPassword1(String password) {this.password1 = password;}; public void setPassword2(String password) {this.password2 = password;}; }RegisterAction: /* * Created on 2006-3-6 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package app;import org.apache.struts.action.*; import javax.servlet.http.*; /** * @author kfzx-yancw * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class RegisterAction extends Action { public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) { // ①Cast the form to the RegisterForm RegisterForm rf = (RegisterForm) form; String username = rf.getUsername(); String password1 = rf.getPassword1(); String password2 = rf.getPassword2(); // ②Apply business logic if (password1.equals(password2)) { return mapping.findForward("success"); }
/*
* Created on 2006-3-6
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package app;import org.apache.struts.action.ActionForm;/**
* @author kfzx-yancw
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class RegisterForm extends ActionForm {
protected String username;
protected String password1;
protected String password2;
public String getUsername () {return this.username;};
public String getPassword1() {return this.password1;};
public String getPassword2() {return this.password2;};
public void setUsername (String username) {this.username = username;};
public void setPassword1(String password) {this.password1 = password;};
public void setPassword2(String password) {this.password2 = password;};
}RegisterAction:
/*
* Created on 2006-3-6
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package app;import org.apache.struts.action.*;
import javax.servlet.http.*;
/**
* @author kfzx-yancw
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class RegisterAction extends Action {
public ActionForward execute (ActionMapping mapping,
ActionForm form,
HttpServletRequest req,
HttpServletResponse res) {
// ①Cast the form to the RegisterForm
RegisterForm rf = (RegisterForm) form;
String username = rf.getUsername();
String password1 = rf.getPassword1();
String password2 = rf.getPassword2();
// ②Apply business logic
if (password1.equals(password2)) {
return mapping.findForward("success");
}
// ④
return mapping.findForward("failure");
}
}
Register 不对吧???
<action path="/register"
type="app.RegisterAction"
name="registerForm"
input="/register.jsp">
<forward name="success" path="/success.html"/>
<forward name="failure" path="/failure.html"/>
</action>
你的<forward name="success" path="/success.html"/>
<forward name="failure" path="/failure.html"/>是不是应该放到
<global-forwards>
</global-forwards>里面?
<struts-config>
<form-beans>
<form-bean name="registerForm" type="app.RegisterForm"/>
</form-beans>
<global-forwards>
<forward name="success" path="/success.html"/>
<forward name="failure" path="/failure.html"/>
</global-forwards>
<action-mappings>
<action path="/register"
type="app.RegisterAction"
name="registerForm"
input="/register.jsp">
<forward name="success" path="/success.html"/>
<forward name="failure" path="/failure.html"/>
</action>
</action-mappings>
</struts-config>
<form-beans>
<form-bean name="registerForm" type="app.RegisterForm"/>
</form-beans>
<global-forwards>
<forward name="success" path="/success.html"/>
<forward name="failure" path="/failure.html"/>
</global-forwards>
<action-mappings>
<action path="/register"
type="app.RegisterAction"
name="registerForm"
input="/register.jsp">
</action>
</action-mappings>
</struts-config>