关于Struts2中DMI(动态调用)错误问题


Struts2之前的版本动态方法调用默认是打开的,没想到2.3.15及之后的版本默认是关闭的,

因此需要启用,编辑struts.xml文件,新增或修改以下信息:

<constant name="struts.enable.DynamicMethodInvocation" value="true" /> 

在网上查询很多结果都是添加这句代码就可以了。

引用:https://www.cnblogs.com/6502ck/p/3984063.html

但是我在使用过程中发现,在最新版本中,这样还是无法访问,还需要添加如下在<package元素 的 首子元素(这里很重要,也就是必须加在apckage的第一个子元素)

<package name="user" namespace="/user" extends="struts-default">
    <!-- 使用DMI需要配置允许的方法 -->
    <global-allowed-methods>add</global-allowed-methods>

    <!-- 访问时:/user/user!add 调用user中的action中的中的add方法,动态方法调用,也叫DMI -->
    
    <action name="user" class="com.actionmethod.CustomActionMethod">
        <result>/userAdd.jsp</result>
    </action>
</package>

引用:https://blog.csdn.net/Liu10010/article/details/72579848

猜你喜欢

转载自www.cnblogs.com/heyunxu/p/12746270.html