RegisterAction
package k.action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.DynaActionForm; import org.apache.struts.actions.DispatchAction; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class RegisterAction extends DispatchAction { public ActionForward doRegister(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { DynaActionForm dynaForm = (DynaActionForm) form; String userName = dynaForm.getString("userName"); String password = dynaForm.getString("password"); String mobile = dynaForm.getString("mobile"); System.out.println("==" + userName + "==" + password + "==" + mobile); return mapping.findForward("registerOk"); } }
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans> <form-bean name="userForm2" type="org.apache.struts.action.DynaActionForm"> <form-property name="userName" type="java.lang.String"></form-property> <form-property name="password" type="java.lang.String"></form-property> <form-property name="mobile" type="java.lang.String"></form-property> </form-bean> </form-beans> <action-mappings> <action name="userForm2" path="/register" parameter="action" type="k.action.RegisterAction" scope="request" attribute="userForm" input="index.jsp" validate="false"> <forward name="registerOk" path="/WEB-INF/jsp/registerOk.jsp"></forward> </action> </action-mappings> </struts-config>
register.jsp
<h1>登录页面</h1> <form action="${APP_PATH}/register.do?action=doRegister" method="post"> 账号:<input type="text" name="userName" value="11哈哈"> <br> 密码: <input type="password" name="password" value="1"> <br> 手机: <input type="text" name="mobile" value="13612341234"> <br> <input type="submit" value="submit"> <br> </form>
registerOk.jsp
<h1>注册成功</h1>