天天看點

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [] associated with con

   今天幫别人調試了一個小問題,我自己做了測試得出來的結果

   錯誤資訊顯示:

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [] associated with con

前提保證web.xml檔案沒有問題,其次保證結果頁面在WebContent 下(一般頁面最好放在一個單獨的檔案夾下,這個檔案夾以WebContentx為父節點)如下圖

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [] associated with con

關于上邊的問題:

首先檢查一下<package>标簽裡邊的 namespace=''/'' 的屬性值裡邊是不是有空格

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [] associated with con

錯誤原因分析,這是說在映射檔案中沒有像上圖紅框裡邊最後部分的命名空間。

補充,在這個裡邊一定不要有空格。

(下圖紅框裡邊的内容是要檢查的部分,我給出的是正确的代碼,我的結果頁面就在page檔案夾下)

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [] associated with con

補充更新:

 之前我覺得我把這個問題了解透了,實則不然,因為今天在做SSH的項目整合的時候,因為不小心的原因,又出現了兩次的錯誤。

 下邊我再對這個問題做一個補充。我以一個錯誤的例子開始幫助分析示範:

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [] associated with con

可以看錯誤上圖的錯誤啊,出現這種錯誤,先看我綠色框裡框起來的内容,錯誤資訊報的是找不到這個名字的映射,框裡的錯誤内容去哪裡找呢?

看下圖,它是和sp頁面裡的action送出的位址:下圖的紅色框裡的内容就是上圖綠色框的提示内容。報上邊的錯誤,就去jsp頁面裡去找錯誤資訊,檢視拼寫,以及檢查是否不小心打了空格。

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [] associated with con

那麼為什麼錯了呢,這就需要去對比struts.xml檔案裡邊檢視相應的映射了(如下圖)正确的是下圖紅框裡的内容和上圖裡邊的應該一緻,特别注意大小寫,我就是因為大小寫錯的。因為我采取通配符的形式,是以隻需要保證下劃線前邊的内容一緻就可以了。

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [] associated with con

錯誤也示範完了,順便再說說Struts2中這些配置以及執行流程吧,請求從jsp頁面開始做第一次送出,

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [] associated with con

然後就去actionMap裡邊去找名字叫做上圖框裡邊名字的映射了,actionMap就是由我們編寫的struts.xml加載來的。然後看struts.xml檔案。

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [] associated with con

紅框裡邊的是jap要找的名字,因為架構的預設加載完得到的是.action字尾的名字,是以jsp檔案裡邊的路徑要帶點action

繼續閱讀