1. 程式人生 > >Spring+Struts2整合:action方法找不到

Spring+Struts2整合:action方法找不到

spring+struts2時jsp頁面執行action時出現找不到Action方法時:

Struts Problem Report

Struts has detected an unhandled exception:

Messages: There is no Action mapped for namespace [/] and action name [userAction_add] associated with context path [/SSHTest].

這個問題困擾了我很久,查了很多資料都是說檢查action方法是不是寫錯,struts.xml配置檔案有沒有寫錯或者放錯位置…
檢查了一遍又一遍自己的程式碼與配置檔案還是不知道問題出在哪。後來無意出看到struts2.3版本的問題,才想起來會不會是版本的問題(本人用的是struts2.5)。

注意:struts2.3以後的版本,為了爭強安全性,是不能直接使用action的方法

所以需要在配置檔案中宣告該方法才能使用:

<!--在<package>標籤下面加上-->
<global-allowed-methods>method</global-allowed-methods>