`
stone_1231
  • 浏览: 38809 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

struts之lookupDispatchAction的使用

阅读更多
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隐藏掉了,呵。
分享到:
评论
2 楼 wood32 2010-05-26  
这个是不是对中文有限制啊
1 楼 oritenson 2010-05-07  
写的还不错,嘻嘻~

相关推荐

Global site tag (gtag.js) - Google Analytics