版本 struts2-core 2.5.1
这是我的请求路径:http://localhost/home/home!home.action
得到的结果如下。
type Status report
message There is no Action mapped for namespace [/home] and action name [home!home] associated with context path [].
description The requested resource is not available.
解决方案
在stuts.xml中配置常量,允许动态访问,这样访问是存在一定安全隐患的,官方不推荐这样访问,所以默认的这个常量取的false。非核心功能可以这样写,减少重复代码。在低版本是不需要这样配置也能动态访问的,我用的版本是struts2-core 2.5.1,需要额外配置
<!--允许动态访问home!login.action-->
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
这样配置之后依然存在问题,但是报错和之前不一样了
type Status report
message Method login for action home is not allowed!
description The requested resource is not available.
参考博客:https://blog.csdn.net/qq_29407009/article/details/51474118
查看源码:从struts-defalt.xml配置文件中看到最后一句话中没有允许login的全局方法
<global-allowed-methods>
execute,input,back,cancel,browse,save,delete,list,index
</global-allowed-methods>
我们在自己的strtus.xml中做如下配置:注意,要放在package的结点中
<global-allowed-methods>login</global-allowed-methods>
再次运行,就访问成功了