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
相關文章
相關標籤/搜索