Struts2动态调用的三种方式

动态调用是为了解决一个Action对应多个请求的处理

1、指定method属性

<action name="save" method="save" class="com.struts.HelloWorldAction">
<result>/save.jsp</result>
</action>

2、感叹号方式

一定要记得添加

<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
<action name="helloworld" class="com.struts.action.HelloWorldAction">
<result>/reuslt.jsp</result>
<result name="save">/save.jsp</result>
</action>

3、通配符方式

result里的name是调用Action后的返回值,action的里method是Action的方法名,调用某个方法时最后目标就输入 {1}_{2}.action;这样可以访问多个Action里的方法

<action name="*_*" method="{2}" class="com.struts.action.{1}Action">
<result>/result.jsp</result>
<result name="save">/{2}.jsp</result>
<result name="delete">/{2}.jsp</result>
</action>

  

猜你喜欢

转载自www.cnblogs.com/tttty/p/11417682.html
今日推荐