问题描述:
在使用action通配符时,不能调转到相应的网页或action
出现:There is no Action mapped for namespace [/] and action name [loginUserAction] associated with context path [/structs2].
解决方法:
以下描述都在struts2.5.14.1版本下。
方法1:直接在package添加
<global-allowed-methods>login</global-allowed-methods>
方法2:修改struts.enable.DynamicMethodInvocation,在action下添加
struts.enable.DynamicMethodInvocation 默认是为 false。
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<allowed-methods>login</allowed-methods>
例:struts.xml配置
<?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">
<struts>
<!-- 动态调用 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<package name="test" namespace="/" extends="struts-default">
<!-- <global-allowed-methods>login</global-allowed-methods> -->
<action name="helloAction" class="com.ldsh.web.action.TestAction" method="hello">
<result name="success" type="redirect">hello.jsp</result>
</action>
<action name="*UserAction" class="com.ldsh.web.action.UserAction" method="{1}">
<result name="success" type="redirect">result.jsp</result>
<allowed-methods>login</allowed-methods>
</action>
</package>
</struts>
注:
1、execute,input,back,cancel,browse,save,delete,list,index这些方法不需配置,即可使用
2、匹配多个和所有
<!-- 匹配多个 -->
<global-allowed-methods>[方法名1][,方法名n]</global-allowed-methods>
<allowed-methods>[方法名1][,方法名n]</allowed-methods>
<!-- 匹配所有 -->
<global-allowed-methods>regex:.*</global-allowed-methods>
<allowed-methods>regex:.*</allowed-methods>
3、struts2的一下默认配置参考
st_struts2-core-2.5.14.1.jar下
变量配置:/org/apache/struts2/default.properties
struts.xml配置:/struts-default.xml