struts LookupDispatchAction的使用

如果一个表单有多个提交,比如加、减、乘、除,那么解决方案有两个(我知道的),第一呢是继承DispatchAction,第二个就是继承LookupDispatchAction。这里我们只说后者

1、需要有一个属性文件,这里我们假设为message.properties

2、在message.properties中加入如下代码。等号前为我们起的中间变量,等号后为jsp页面的value值
button.add=ADD
button.sub=SUB
button.mul=MUL
button.div=DIV

3、jsp页面代码如下:
<input type="submit" name="method" value="ADD"/>
<input type="submit" name="method" value="SUB"/>
<input type="submit" name="method" value="MUL"/>
<input type="submit" name="method" value="DIV"/>


4、在struts-config.xml 中需要配置parameter
<action path="" type=""      parameter="method"  name=""/>

5、最后我们实现Action中未实现的方法
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("button.add", "add");
map.put("button.sub", "sub");
map.put("button.mul", "mul");
map.put("button.div", "div");
return map;
}
put方法的第一个参数为我们起的中间变量,第二个参数即为我们要访问的方法

6、执行顺序,以除为例:jsp(value="DIV")----message.properties(button.div)----**Action(div方法)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值