整理實戰中高頻出現的異常、報錯場景與解決思路,方便快速定位問題。
The requested resource (/project/hello.action) is not available.
web.xml / struts.xml 映射錯誤。Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
spring-web.jar)。Spring 3.0/4.x Web Library;或 Maven 加入 spring-web 依賴。StandardServer.await: create[8005]: java.net.BindException: Address already in use
netstat -ano | findstr 8080 找出 PID,任務管理器結束進程。server.xml 更改 Connector port 與 Server port。Object o = session.getAttribute("key");
List list = (List) o; // 報錯
instanceof 判斷,或統一存放型別;若確定為單值,改用 String val = (String) o 再封裝進 List。.metadata/.plugins/org.eclipse.core.runtime/.settings/com.genuitec.eclipse.ast.deploy.core.prefs。DeploymentBuilder 關閉自動部署。javaee.jar(或 servlet-api.jar)。order by 前缺空格)。PreparedStatement 或 MyBatis 參數綁定,避免手動拼接;若必須拼接,打印完整 SQL 檢查空格與保留字。com.genuitec.eclipse.ast.deploy.core.prefs 並重啟。Type Action question!list cannot be found in the namespace /
Struts2 Validator 的 Build 勾選(或全部 Build 勾選移除)。核心排錯心法: 異常堆疊最頂層的 Caused by 通常是根因;善用 Google/StackOverflow 搜尋關鍵錯誤訊息(勿貼整串堆疊);養成「一步驗證、一步整合」習慣,將問題域縮至最小。