首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計綜合問答

SSH 整合訪問 Action 返回 404:struts.xml 中 namespace/action 映射缺失

     編輯:程式設計綜合問答

現象:JSP 正常訪問,Action 返回 404,Tomcat 無錯誤,Action 斷點不進入。

核心排查

  1. 檢查 web.xml Filter 映射:
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    確保攔截所有請求。
  2. struts.xml 中 package namespace:
    若 <package name="..." namespace="/user">,則訪問路徑需為 /user/xxx.action。
  3. action name 與 url-pattern 後綴一致:
    Struts2 默認 *.action,若改為 *.do 需在 struts.properties 配置 struts.action.extension=do。
  4. Action 類全限定名正確:
    <action name="login" class="com.xxx.action.LoginAction"> 類名拼寫、包路徑無誤。

快速定位技巧

  • 啟動項目,訪問 https://localhost:8080/項目名/struts-config-browser/index.jsp(需加 struts2-config-browser-plugin 依賴),查看所有 Action 映射。
  • 控制台日志設置 log4j.logger.org.apache.struts2=DEBUG 觀察 Action 解析過程。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved