struts2.5的method使用通配符无效问题

struts2.5版本引入了新的安全限制(据说是2.3版本开始,没去确认

新版本通配符需要配置才能使用

两种方法

1、关闭严格方法调用

    ....
    <package name = "default" namespace="/" extends="struts-default" strict-method-invocation="false">
    ....

等于说放弃了新引进的DMI机制,一劳永逸,但有风险(不过想想原来都是这样用的……

2、设定方法白名单

  • xml配置
    //设定全局允许通行的方法
    <global-allowed-methods>method1,method2</global-allowed-methods>
    //每个action单独设定
    <action name="test_*" method="{1}" class="com.test.TestClass">
    <result name="success">{1}page.jsp</result>
    <allowed-methods>method1,metho2</allowed-methods>
    </action>

  • 注解方式
    //注解加在action类上
    @AllowedMethods("method")
    public class TestAction extends ActionSupport {
    ......
    }

第二种方式需要维护方法白名单,是官方推荐的做法

参考官网的说明

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容