struts2 回顾

Action动态方法调用的三个方式:(动态方法调用就是为了解决一个Action对应对个请求的处理,以免Action太多)
1)指定method属性;

<action name="add" method="add" class="com.imooc.action.HelloWorldAction">
<result>/add.jsp</result>
</action>

2)感叹号方式(官方不太推荐);
先在package外面添加:
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>

<action name="helloworld" class="com.imooc.action.HelloWorldAction">
<result>/reuslt.jsp</result>
<result name="add">/add.jsp</result>
</action>

访问add方法则地址最后目标改为:helloworld!add.action

3)通配符方式。(推荐方式)
第一个代替{1},第二个代替{2},result里的name是Action的返回值,action的里method是Action里的方法名,调用某个方法时最后目标就输入 {1}_{2}.action;这样可以访问多个Action里的方法

<action name="*_*" method="{2}" class="com.imooc.action.{1}Action">
<result>/result.jsp</result>
<result name="add">/{2}.jsp</result>
<result name="update">/{2}.jsp</result>
</action>

浏览器地址:
http://localhost:8080/HelloWorld/helloworld_add.action,则请求的是add.jsp
此方式可以灵活运用,可以用于class的包名、类名、以及Action的name属性中占位

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值