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

Tomcat 部署 JSP 專案 404 錯誤:MyEclipse 配置、struts.xml 版本對應與 webapps 結構檢查

     編輯:程式設計綜合問答

Tomcat 啟動正常但訪問 JSP 回傳 404,排查路徑:專案部署路徑正確 → MyEclipse Server 配置無誤 → struts.xml DTD 版本匹配 → Action 映射路徑正確。

檢查清單

  1. 專案發布路徑:
    MyEclipse → 專案右鍵 → Properties → MyEclipse → Web → Web Root 設定正確 (通常為 WebRoot 或 src/main/webapp)。
    Deployment → 專案名稱對應 URL 前綴 (如 /MyProject)。
  2. Tomcat webapps 目錄:
    啟動後 webapps/MyProject 目錄是否存在?內含 WEB-INF/web.xml、classes、lib?
  3. struts.xml DTD 宣告:
    必須與 Struts2 版本完全對應,否則配置不生效:
    Struts 2.5.x:
    <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "https://struts.apache.org/dtds/struts-2.5.dtd">
    Struts 2.3.x:
    <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "https://struts.apache.org/dtds/struts-2.3.dtd">
  4. Action namespace 與 URL:
    <package name="default" namespace="/" ...> 對應 https://localhost:8080/MyProject/actionName.action。
  5. web.xml Filter 配置:
    <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> (2.5+) 或 FilterDispatcher (舊版)。

快速驗證法

  • 在 WebRoot 新建 test.jsp 內容 <%= "OK" %>,訪問 /MyProject/test.jsp。若 404 → 部署路徑/Server 配置錯。若 OK → Struts/Action 映射錯。
  • 使用官方 struts2-blank.war 解壓參考標準結構。
  • 參考資源

    系統性檢查「部署→配置→映射」三層,能精準定位 404 根因。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved