浏览 2040 次
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2010-01-13
最后修改:2010-01-13
<%-- 这里根据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 stub System.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 stub System.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 stub System.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隐藏方法名 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |