struts 找不到action 的可能缘由

struts版本2.5.13,配置以下html


<?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>
    <package name="app" namespace="/" extends="struts-default">
        <action name="userAction_*" class="web.actions.UserAction" method="{1}">
            <result>/success.jsp</result>
        </action>
    </package>

</struts>


访问 http://localhost/userAction_add 提示没法找actionweb


HTTP Status 404 - There is no Action mapped for namespace [/] and action name [userAction_add] associated with context path [].
type Status report
message There is no Action mapped for namespace [/] and action name [userAction_add] associated with context path [].
description The requested resource is not available.
Apache Tomcat/7.0.82


struts为了安全,限制了Action被调用的方法,以下配置可正常访问:正则表达式


<?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>
    <package name="app" namespace="/" extends="struts-default">
        <global-allowed-methods>regex:.*</global-allowed-methods> <!-- 方法一 -->
        <action name="userAction_*" class="web.actions.UserAction" method="{1}">
            <result>/success.jsp</result>
            <allowed-methods>regex:.*</allowed-methods> <!-- 方法二 -->
        </action>
    </package>

</struts>
标签<global-allowed-methods>和<allowed-methods>中但是使用regex:开头的正则表达式,来表示容许被执行的Action方法,regex:.*表示任何方法均可以被调用;
也能够将容许被调用的方法名放入其中,多个方法用逗号隔开,如:add,delete
相关文章
相关标签/搜索