<form action="addUser" method="post"> ... </form>
Servlet 映射:@WebServlet("/addUser") → URL 為 https://host:port/專案/addUser。
若 JSP 位於 /page/register.jsp,表單提交實際請求 /page/addUser → 404。
<form action="${pageContext.request.contextPath}/addUser" method="post">
<form action="../addUser" method="post"> // 從 /page/ 回上層
@WebServlet("/page/addUser")
<%@ taglib prefix="c" uri="https://java.sun.com/jsp/jstl/core" %>
<form action="<c:url value='/addUser'/>" method="post">
<c:url> 自動補上 contextPath 並處理編碼。
webapps 目錄)。web.xml 與註解衝突(Servlet 3.0+ 可無 web.xml)。表單 action 路徑必須與 Servlet 映射 URL 完全一致。使用 ${pageContext.request.contextPath} 或 <c:url> 產生絕對路徑,可徹底避免相對路徑導致的 404 問題。