当前位置:编程学习 > JSP >>

struts的lookupDispatchAction的使用

 org.apache.struts.actions.LookupDispatchAction类别是 DispatchAction 类别的子类,与DispatchAction类似的是,它透过请求上的参数来决定该执行哪一个方法,不过LookupDispatchAction多了查 询讯息资源档案的功能,LookupDispatchAction的用处之一,就是当一个表单中包括两个以上的按钮时,可以透过查询讯息资源档来确定相对 应的动作。直接以实例来说明,在继承LookupDispatchAction之後,您要重新定义getKeyMethodMap()方法,并定义好自己的相关处理方法,例如:EditAction.java package onlyfun.caterpillar;import javax.servlet.http.*; import org.apache.struts.action.*; import org.apache.struts.actions.*;public class EditAction extends LookupDispatchAction { protected Map getKeyMethodMap() { Map map = new HashMap(); map.put("button.save", "save"); map.put("button.preview", "preview"); map.put("button.reset", "reset"); return map; } public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // ...... } public ActionForward preview(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // ...... } public ActionForward reset(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // ...... } }假设讯息资源档中包括以下的讯息:messages.properties button.save=Savebutton.preview=Previewbutton.reset=Reset为了要使用LookupDispatchAction,在struts-config.xml中定义请求参数中该有的名称:struts-config.xml ... ... 现在假设您的表单页面包括以下的内容:...
.....
...当您按下任一个按钮时,请求参数中会包括method=Save或是method=Preview或是method= Reset,假设是method=Save好了,
补充:Jsp教程,Java技巧及代码 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,