今天使用LookupDispatchAction時,由於編寫的類繼承LookupDispatchAction,同時也覆蓋其execute()方法,結果導致自己編寫的邏輯函數不起作用,把覆蓋execute()方法的代碼去掉即可實現同名按鈕提交分別處理的效果,下面是代碼:
JSP檔案
<%@ page contentType="text/html; charset=GBK" %>
<%@ include file="taglib.jsp" %>
<html>
<head>
<title>
jsp7
</title>
</head>
<body bgcolor="#ffffff">
<html:form action="/processCheckoutAction.do">
<html:text property="abc">
</html:text>
<html:submit property="action"><bean:message
key="welcome.user"/></html:submit>
<html:submit property="action"><bean:message
key="goodbye.user"/></html:submit>
</html:form>
</body>
</html>
擴充的LookupDispatchActionpublic class ProcessCheckoutAction extends LookupDispatchAction ...{
protected Map getKeyMethodMap()...{
Map map=new HashMap();
map.put("welcome.user","saveorder");
map.put("goodbye.user","checkout");
return map;
}
public ActionForward saveorder(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)...{
System.out.println("saveorder");
return (mapping.findForward("success1"));
}
public ActionForward checkout(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)...{
System.out.println("checkout");
return (mapping.findForward("success2"));
}
}
Struts-config.xml相應的配置
<action name="untitled2ActionForm" parameter="action"
path="/processCheckoutAction" scope="request"
type="test.ProcessCheckoutAction" validate="true">
<forward name="success1" path="/jsp5.jsp" />
<forward name="success2" path="/jsp6.jsp" />
</action>