Messages:This method: edit for action XXX is not allowed!-Struts2.5动态方法调用错误解决方法
2017-09-23 16:42
1386 查看
struts.xml部分配置
Action部分代码
报错信息
解决方案
此处查阅了大量文章,还有struts官方文档:struts2:This method: login for action user is not allowed!
在struts2.5版本中使用DMI遇到问题
Struts 2.5 动态方法调用(DMI)问题
Apache Struts 2 Documentation Action Configuration
解决方法无非是在配置文件中添加
<global-allowed-methods>regex:.*</global-allowed-methods>
例如我的struts.xml中配置:
<package name="yong" extends="struts-default"> <!-- 配置自定义拦截器LoginedCheckInterceptor --> <interceptors> <interceptor name="loginedCheck" class="com.yong.struts.interceptor.LoginedCheckInterceptor" /> </interceptors> <!--struts2.5之后要添加此属性才能访问action,方法名以逗号隔开,或使用正则匹配--> <global-allowed-methods>regex:.*</global-allowed-methods> </package>
或者,针对action,在 action 块中添加
<allowed-methods>regex:.*</allowed-methods>
同样,也支持在你的 action 上使用
@AllowedMethods注解
struts-default默认的设置为
<global-allowed-methods>execute,input,back,cancel,browse,save,delete,list,index</global-allowed-methods>
全局设置是增量而不是覆盖的,支持正则和直接匹配方法,
源码在这两段
// com.opensymphony.xwork2.DefaultActionProxy#prepare // com.opensymphony.xwork2.config.entities.ActionConfig#isAllowedMethod
但是经过这样的配置之后总是不生效,经过排查发现在action中使用了
@ParentPackage(value = "struts-default")注解,这样的话只支持struts-default默认的方法通过。将这里改为:
@ParentPackage(value = "yong")
value为你自定义package的名称,继承自struts-default。这样便可使上述的配置生效。
吐槽:struts2真是大坑,每次因为爆出安全漏洞而升级版本都会出现各种问题。
相关文章推荐
- Struts2.5动态方法调用 错误Messages:This method: edit for action product is not allowed!解决方法
- struts2 2.5动态方法调用(DMI) dynamic method invoke 出现不被允许的方法时 Method add for action dynamic is not allowed! - [unknown location]
- Struts2-动态方法调用-Could not find action or result-Method update for action user is not allowed
- Struts2中DMI(动态方法调用)的错误问题(There is no Action mapped for namespace [/xxx] and action name [xxx!yyy] a)
- this class is not key value coding-compliant for the key XXX错误的解决方法
- this class is not key value coding-compliant for the key XXX错误的解决方法
- this class is not key value coding-compliant for the key XXX错误的解决方法
- this class is not key value coding-compliant for the key XXX错误的解决方法
- Struts应用出现的错误及解决方法:There is no Action mapped for namespace / and action name login
- this class is not key value coding-compliant for the key XXX错误的解决方法
- 每当使用struts2动态方法调用时,总是出现错误:There is no Action mapped for namespace [/user] and action name [user!add]
- this class is not key value coding-compliant for the key XXX错误的解决方法
- struts2 DMI用感叹号动态调用方法时提示there is no action mapped for
- 关于eclipse+struts action找不到问题解决方法 There is no Action mapped for namespace
- spring 加载时的Content is not allowed in prolog. 错误解决方法
- [置顶] Unable to add window -- token null is not for an application错误的解决方法 android开发
- Struts2错误:There is no Action mapped for namespace... 解决方法
- Delphi出现“borland license information was found,but it is not valid for delphi”的错误,无法运行的解决方法
- Servlet Action is not available 错误的其他可能原因和解决方法
- this class is not key value coding-compliant for the key Button 错误解决方法