DispatchAction的使用
DispatchAction的使用:
* DispatchAction中的execute方法,如果覆盖必须显示调用super.execute()
* parameter参数值不能是execute和perform
* <action>标签中的parameter的含义
:parameter="method"
* 了解DispatchAction中的unspecified方法的含义
:在没有指定方法名的时候采用
public class LoginAction extends DispatchAction { public ActionForward loginValidate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { LoginForm loginForm = (LoginForm) form; ActionForward forward = new ActionForward(); ... return forward; } public ActionForward deleteUser(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { LoginForm loginForm = (LoginForm) form; ActionForward forward = new ActionForward(); ... return forward; }}<html:form action="/loginAction.do?method=loginValidate" method="POST"> 用户名: <html:text property="au_lname"/> <br> <html:submit property="submit" value="Submit"/> <br> <html:reset value="Reset"/> </html:form>验证信息。
<html:form action="/loginAction.do?method=deleteUser" method="POST"> 用户名: <html:text property="au_lname"/> <br> <html:submit property="submit" value="Submit"/> <br> <html:reset value="Reset"/> </html:form>
<action-mappings> <action name="loginForm" parameter="method" path="/loginAction" scope="request" type="com.aptech.dispatchactiondemo.action.LoginAction"> <forward name="error" path="/error.jsp" /> <forward name="success" path="/success.jsp" /> <forward name="deletesuccess" path="/deletesuccess.jsp" /> </action></action-mappings>
...<h1>下面表单中的“添加”和“修改”按钮都可以提交表单,但不是JSF</h1><p> <html:form action="/demoAction.do" method="POST"> <%--提交的路径还是*.do --%> userName: <html:text property="userName"/> <br> password: <html:password property="password"/> <br> <input type="hidden" name="method" value="add"/> <%-- 添加了一个hidden隐藏文本域,name的值method与 struts-config.xml里面的parameter的值method相同 --%> <input type="submit" onclick="method.value='add'" value="添加"/> <input type="submit" onclick="method.value='modify'" value="修改"/> <%--两个sumbit按钮,在onclick方法上更改method的值--%> </html:form>...
<action path= "/registerEmployee " input= "/registerEmployee.jsp " parameter= "method " name= "employeeForm " attribute= "employeeForm " scope= "request " validate= "true " type= "com.xyh.emp.EmployeeDispatchAction "> <forward name= "detail " path= "/detailEmployeeInfo.jsp " /> </action> <action path= "/editEmployee " input= "/editEmployee.jsp " parameter= "method " name= "employeeForm " attribute= "employeeForm " scope= "request " validate= "true " type= "com.xyh.emp.EmployeeDispatchAction "> <forward name= "detail " path= "/detailEmployeeInfo.jsp " /> </action>