lookupDispatchAction用途之一:当jsp中有多个相同名字的按钮时
jsp:
<body>
<html:form action="/my">
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="save"/>
<input type="submit" name="method" value="delete"/>
<input type="submit" name="method" value="search"/>
</html:form>
</body>
action:
public class MyAction extends LookupDispatchAction {
...
public ActionForward saveAction(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
MyForm myForm = (MyForm) form;// TODO Auto-generated method stub
System.out.println("MyAction...save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)");
return mapping.findForward("succ");
}
public ActionForward deleteAction(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
MyForm myForm = (MyForm) form;// TODO Auto-generated method stub
System.out.println("MyAction...delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)");
return mapping.findForward("succ");
}
public ActionForward searchAction(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
MyForm myForm = (MyForm) form;// TODO Auto-generated method stub
System.out.println("MyAction...search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)");
return mapping.findForward("succ");
}
/**
* 必须覆盖
*/
protected Map getKeyMethodMap() {
// TODO Auto-generated method stub
/**
* key对应ApplicationResources.properties中=前面
* value对应action中的方法名
*
* ApplicationResources.properties中=后面对应jsp按钮value
*/
Map<String, String> m = new HashMap<String, String>();
m.put("button.save", "saveAction");
m.put("button.delete", "deleteAction");
m.put("button.search", "searchAction");
return m;
}
Struts-config.xml
记得加上
parameter="method"
ApplicationResources.properties:
button.save=save
button.delete=delete
button.search=search
有一点可以看到,地址栏里面没有显示方法名../../my.do隐藏掉了,呵。
分享到:
相关推荐
充分描述LookupDispatchAction 的使用!对学习者很有帮助。
List_Map_LookupDispatchAction_Validate的使用~ 具体内容浏览giddy的MSN Space
struts1学习资料:里面包含struts源码工程 ActionServlet DispatchAction Action LookUpDispatchAction的用法 还包含html logic bean tiles标签的详细使用方法和validate验证框架的具体案例
JavaEE框架 Struts_In_Action(中文版) Struts Action Struts_In_Action LookupDispatchAction DispatchAction 对Action讲的比较仔细,可以深入的了解Struts框架里的基本原理。
struts1.x和mysql整合的登陆例子,包括用户的增删改查,涉及到LookupDispatchAction,的多个submit提交,静态验证,和读取数据库properties文件
DispatchAction的作用简单地说就是把原来我们写在多个acton里的操作放在同一个 action里处理。
大部分基于B/S结构的web应用系统中,在页面上经常会出现一个以上的功能按钮,而这些功能按钮基本上都是对应于后台的一个操作实现,由于在本系统中的表现层选用较为成熟Struts框架,该框架中最为核心的部分要属控制器...