zoukankan      html  css  js  c++  java
  • 关于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

    以下引用有详细说明:

    在struts2.3之前的版本,正常的配置就可以了,但在struts2.3版本之后,使用通配符调用方法时,内部会验证是否允许访问该方法。

    1、struts2.5 为了增加安全性,在 struts.xml 添加了这么个属性:<global-allowed-methods>regex:.*</global-allowed-methods>,例子如下:

    <package name="default" extends="struts-default" namespace="/index" >
        <global-allowed-methods>regex:.*</global-allowed-methods>
    
        <action name="User_add" class="com.wg.struts2.UserAction" >
            <result>/user/addUser.jsp</result>
        </action>
    
        <action name="*_*" class="com.wg.struts2.{1}Action" method="{2}">
            <result>/user/{2}{1}.jsp</result>
        </action>
    
        <action name="help" >
            <result>/help.jsp</result>
        </action>
    </package>

    2、当使用动态调用方法时(action名 + 感叹号 + 方法名进行方法调用),如:<a href="<%=context %>/index/User_add!add">添加用户</a><br />,则需要在配置文件中加上配置:

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

    引用:https://www.cnblogs.com/junwangzhe/p/7094524.html

    之所以成功,因为有坚持。。。
  • 相关阅读:
    APP开发的模式
    微信小程序的传值方式
    面试题总结
    github上传文件的步骤
    python使用笔记15--操作Excel
    python使用笔记14--商品管理小练习
    python使用笔记13--清理日志小练习
    python使用笔记12--操作mysql数据库
    python使用笔记11--时间模块
    python使用笔记10--os,sy模块
  • 原文地址:https://www.cnblogs.com/heyunxu/p/12746270.html
Copyright © 2011-2022 走看看