【J2EE】Struts2.5.10 无法进入Action类的指定方法

Struts2.5.10 版本为了安全考虑 默认是不允许DMI(动态方法访问)的

  解决办法:

    step1.

      struts 标签下添加 <constant name="struts.enable.DynamicMethodInvocation" value="true"/>   //允许DML

    step2.  

      //以下四种选择根据需要选择

      <a> action 标签下添加 <allowed-methods>regex:.*</allowed-methods>     //允许DML指定action类方法

      <b> package标签下添加  action <allowed-methods>regex:.*</allowed-methods>    //允许DML所有action类方法:

      <c> 如果想要设置指定方法

          1. 给package标签设置 strict-method-invocation="true"

          2.action 标签下添加 <allowed-methods>方法名</allowed-methods>     //允许DML指定方法

      <d> 设置action标签的method属性(默认为execute)

 另外:

  *如果向再配置文件中使用通配符访问,则需给package标签添加strict-method-invocation="false"

 demo 如下

-------------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC     "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"     "http://struts.apache.org/dtds/struts-2.5.dtd">

<!-- START SNIPPET: xworkSample -->

<struts>    

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

   <package name="struts2" extends="struts-default">    

     <global-allowed-methods>regex:.*</global-allowed-methods>    

     <action name="act1" class="Action.Act1">         

       <result name="page2">/page2.jsp</result>       

       <!--<allowed-methods>regex:.*</allowed-methods> -->          

      </action>         

   </package>

</struts>

原文地址:https://www.cnblogs.com/LightChan/p/7139815.html