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隐藏掉了,呵。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值