美文网首页
struts2.5的method使用通配符无效问题

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

作者: CRitsu | 来源:发表于2016-12-05 01:39 被阅读0次

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 {
    ......
    }

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

参考官网的说明

相关文章

网友评论

      本文标题:struts2.5的method使用通配符无效问题

      本文链接:https://www.haomeiwen.com/subject/fdrkmttx.html