stone_1231 发表于 2013-2-6 08:07:00

struts之MappingDispatchAction的使用

jsp:
<%--这里根据action的不同值(与struts-config.xml中path值对应)调用不同的方法--%><%--<html:form action="/mapDelete.do">--%><%--<html:form action="/mapSave.do">--%><html:form action="/mapSearch.do">age : <html:text property="age"/><html:errors property="age"/><br/>name : <html:text property="name"/><html:errors property="name"/><br/><input type="submit" name="method" value="search"/> </html:form>

action:
public class MapAction extends MappingDispatchAction {...public ActionForward saveAction(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {MapForm mapForm = (MapForm) form;// TODO Auto-generated method stubSystem.out.println("MapAction...save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)");return mapping.findForward("succ");}public ActionForward deleteAction(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {MapForm mapForm = (MapForm) form;// TODO Auto-generated method stubSystem.out.println("MapAction...delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)");return mapping.findForward("succ");}public ActionForward searchAction(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {MapForm mapForm = (MapForm) form;// TODO Auto-generated method stubSystem.out.println("MapAction...search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)");return mapping.findForward("succ");}

struts-config.xml
    <action      attribute="mapForm"      input="/jsp/map.jsp"      name="mapForm"      path="/mapSave"      parameter="saveAction"      scope="request"      type="com.zhangl.struts.action.MapAction">    <forward name="succ" path="/jsp/succeed.jsp"></forward>      </action>      <action      attribute="mapForm"      input="/jsp/map.jsp"      name="mapForm"      path="/mapDelete"      parameter="deleteAction"      scope="request"      type="com.zhangl.struts.action.MapAction">    <forward name="succ" path="/jsp/succeed.jsp"></forward>      </action>      <action      attribute="mapForm"      input="/jsp/map.jsp"      name="mapForm"      path="/mapSearch"      parameter="searchAction"      scope="request"      type="com.zhangl.struts.action.MapAction">    <forward name="succ" path="/jsp/succeed.jsp"></forward>      </action>


DispatchAction继承Action
LookupDispatchAction MappingDispatchAction都是继承DispatchAction
三者都可以实现一个action类对应多个应用

struts-config.xml中
DispatchAction一个配置
LookupDispatchAction一个配置
MappingDispatchAction多个配置
parameter=“”前两者对应为参数名,第三者为方法名。

继承LookupDispatchAction的action需覆盖方法protected Map getKeyMethodMap()
并配置ApplicationResources.properties。

ie地址栏
DispatchAction显示方法名
LookupDispatchAction MappingDispatchAction隐藏方法名
页: [1]
查看完整版本: struts之MappingDispatchAction的使用