首页 > 其他 > 详细

struts2.5动态方法调用和默认Action

时间:2017-01-12 02:33:56      阅读:294      评论:0      收藏:0      [点我收藏+]

在动态方法调用中,使用通配符方法出现问题,参考了http://www.cnblogs.com/jasonlixuetao/p/5933671.html 这篇博客,问题解决了。

这个是helloworld.xml:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
 4     "http://struts.apache.org/dtds/struts-2.5.dtd">
 5  
 6 <struts>
 7     <package name="default" namespace="/" extends="struts-default">
 8         <global-allowed-methods>regex:.*</global-allowed-methods>
 9         <action name="*_*_*" method="{2}" 
10                 class="com.imooc.{3}.{1}Action">
11             <result>/result.jsp</result>
12             <result name="add">/{2}.jsp</result>
13             <result name="update">/{2}.jsp</result>
14         </action>
15     </package>
16 </struts>

在struts.xml中包含了这个文件:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
 4     "http://struts.apache.org/dtds/struts-2.5.dtd">
 5  
 6 <struts>
 7 
 8     <include file="helloworld.xml"></include>
 9     <constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>
10     
11 </struts>

解决2.5版本通配符的动态方法调用就是加上了这一句:

<global-allowed-methods>regex:.*</global-allowed-methods>

但是,问题来了,在使用默认Action时,加上这一句就会报错,不加就可以正常运行,下面是正常运行的helloworld.xml:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
 4     "http://struts.apache.org/dtds/struts-2.5.dtd">
 5  
 6 <struts>
 7     <package name="default" namespace="/" extends="struts-default">
 8         
 9         <default-action-ref name="index"></default-action-ref>
10         <action name="index">
11             <result>/error.jsp</result>
12         </action>
13         
14         <action name="*_*_*" method="{2}" 
15                 class="com.imooc.{3}.{1}Action">
16             <result>/result.jsp</result>
17             <result name="add">/{2}.jsp</result>
18             <result name="update">/{2}.jsp</result>
19         </action>
20     </package>
21 </struts>

又发现,也只能运行默认的action,并不能调用到add或update方法。

技术分享

 

struts2.5动态方法调用和默认Action

原文:http://www.cnblogs.com/AmazingSally/p/6274020.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!