struts 2.5 action的多分发 ---动态方法调用
2016-10-16 18:11
344 查看
动态方法调用
在Struts2中动态方法调用有三种方式,动态方法调用就是为了解决一个Action对应多个请求的处理,以免Action太多
1、第一种方式:指定method属性
这种方式我们前面已经用到过,类似下面的配置就可以实现
<action name="chainAction" class="chapter2.action.Chapter2Action"
method="chainAction">
<result name="chainAction" type="chain">redirect</result>
</action>
<action name="plainText" class="chapter2.action.Chapter2Action"
method="plainText">
<result name="plainText" type="plainText">/WEB-INF/JspPage/chapter2/plaintext.jsp</result>
</action>
2、第二种方式:感叹号方式(需要开启),官网不推荐使用这种方式,建议大家不要使用.
用这种方式需要先开启一个开关
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
3、第三种方式:通配符方式(官网推荐使用)
首先得关闭开关
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
这一种方式是由第一种转变过来的,我们可以看到,第一种方式有很多重复的代码,那么我们可以进行变形,看下面的代码
<action name="chapter3_*" class="chapter3.action.Chapter3Action"
method="{1}">
<result name="test">/…/test.jsp</result>
</action>
在Struts2中动态方法调用有三种方式,动态方法调用就是为了解决一个Action对应多个请求的处理,以免Action太多
1、第一种方式:指定method属性
这种方式我们前面已经用到过,类似下面的配置就可以实现
<action name="chainAction" class="chapter2.action.Chapter2Action"
method="chainAction">
<result name="chainAction" type="chain">redirect</result>
</action>
<action name="plainText" class="chapter2.action.Chapter2Action"
method="plainText">
<result name="plainText" type="plainText">/WEB-INF/JspPage/chapter2/plaintext.jsp</result>
</action>
2、第二种方式:感叹号方式(需要开启),官网不推荐使用这种方式,建议大家不要使用.
用这种方式需要先开启一个开关
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
3、第三种方式:通配符方式(官网推荐使用)
首先得关闭开关
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
这一种方式是由第一种转变过来的,我们可以看到,第一种方式有很多重复的代码,那么我们可以进行变形,看下面的代码
<action name="chapter3_*" class="chapter3.action.Chapter3Action"
method="{1}">
<result name="test">/…/test.jsp</result>
</action>
相关文章推荐
- Struts2.5动态方法调用 错误Messages:This method: edit for action product is not allowed!解决方法
- Messages:This method: edit for action XXX is not allowed!-Struts2.5动态方法调用错误解决方法
- Struts2.5动态方法调用action和使用通配符访问action
- 升级Struts2.5后使用DMI动态方法调用遇到问题
- Struts2.5 动态方法报错 找不到Action
- Struts2.5使用感叹号实现动态方法调用无效的解决办法
- Struts-2.5 Action动态调用与通配调用无效解决办法
- 升级Struts2.5后使用DMI动态方法调用遇到问题
- struts2.5 使用感叹号和通配符实现动态方法调用无效的问题及解决!
- Struts2.5使用通配符的方式实现动态方法调用报错
- (action动态方法调用)struts通过ActionName!methodName.action,即通过感叹号(即!)访问某Action的方法,确老是报错
- 【Struts】Action 3 动态方法调用
- struts2.5动态方法调用不能使用问题
- Struts 2读书笔记-----使用Action的动态方法调用
- struts的Action接口-- (1)动态方法调用
- struts2 2.5动态方法调用(DMI) dynamic method invoke 出现不被允许的方法时 Method add for action dynamic is not allowed! - [unknown location]
- Struts2 方法动态调用,验证表签,xml配置Action
- Struts 2读书笔记-----使用Action的动态方法调用
- 解决Struts2.5不能使用通配符方式动态方法调用
- Struts 2读书笔记-----使用Action的动态方法调用