Struts2.5版本方法沒法使用通配符問題

問題:在struts2.5中若是使用方法通配符,是沒法進行方法調用的:jsp

<action name="login_*" class="loginAction" method="{1}">
.............
</action>

由於從2.3開始在package元素中增長了一個屬性,爲了限制DMI的方法訪問:spa

<package name="test" namespace="/test" extends="struts-default" strict-method-invocation="">
..................
</package>

默認狀況下是沒有設置值,因此2.3是能夠進行調用的。可是到了2.5之後默認設置爲true,因此從2.5開始默認狀況下是沒法進行通配符方法調用的。修改的方式:code

一、xml

<package name="test" namespace="/test" extends="struts-default" strict-method-invocation="false">
</package>

二、io

<package name="test" namespace="/test" extends="struts-default" strict-method-invocation="true">
	<action name="electricText_*" class="electricTextAction" method="{1}">
	    <result name="{1}">/system/textAdd.jsp</result>
            <allowed-methods>添加Action類中容許訪問的方法,以逗號分隔</allowed-methods>
	</action>
</package>

在不啓用的狀況下,注意默認的匹配規則是: SMI is disabled - call to any action method is allowed that matches the default RegEx - ([A-Za-z0-9_$]*)class

能夠經過定義常量更改,在struts.xml中:test

<constant name="struts.strictMethodInvocation.methodRegex" value="([a-zA-Z]*)"/>
相關文章
相關標籤/搜索