struts2.5的method使用萬用字元無效問題
阿新 • • 發佈:2019-02-01
struts2.5版本引入了新的安全限制(據說是2.3版本開始,沒去確認)
新版本萬用字元需要配置才能使用
兩種方法
1. 關閉嚴格方法呼叫
....
<package name = "default" namespace="/" extends="struts-default" strict-method-invocation="false">
....
等於說放棄了新引進的DMI機制,一勞永逸,但有風險(不過想想原來都是這樣用的……
2. 設定方法白名單
- xml配置
//設定全域性允許通行的方法
<global-allowed-methods >method1,method2</global-allowed-methods>
//每個action單獨設定
<action name="test_*" method="{1}" class="com.test.TestClass">
<result name="success">{1}page.jsp</result>
<allowed-methods>method1,metho2</allowed-methods>
</action>
- 註解方式
//註解加在action類上
@AllowedMethods ("method")
public class TestAction extends ActionSupport {
......
}
第二種方式需要維護方法白名單,是官方推薦的做法