struts2 DMI无法运行

初学struts,在学习动态方法调用的时候,写的链接为<a href="user/user!list">添加学生</a>

但是在点击链接时,出现下面这样的错误提示信息:

There is no Action mapped for namespace [/user] and action name [user!add] associated with context path [/Struts2_050_ActionMethod]

查了文档才知道,原来struts2出于两方面的考虑,对DMI可以选择enable和disable:1)DMI可能导致安全问题;2)DMI与通配符方法功能有重叠。

但是默认情况下,DMI是enable的。

仔细看了下我的配置文件,发现原来拷贝其他文件时,多拷贝了这么一句话

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

这句话就将DMI设置成了disable了。

删除这句话,或者把value改成“true”,就能得到正常想要的结果了。

在struts.xml中添加

<constant name="struts.enable.DynamicMethodInvocation" value="true" /> 
打开动态方法调用。
动态方法调用官方推荐的做法是,使用通配符的形式。不要使用actionName!methodName
的方式。

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

原文地址:https://www.cnblogs.com/6502ck/p/3984063.html