Tomcat的默認訪問路徑為http://localhost:8080,后需添加項目路徑。
請求轉發,是轉發到本項目中的其他文件,所以在默認訪問路徑中添加了本項目的項目路徑,故可以省略項目名稱:
request.getRequestDispatcher ("/register.jsp");
重定向可以轉到非本項目的資源,項目名不可省略:
response.sendRedirect (request.getContextPath ()+"/login.jsp");
在jsp文件中,由於不知道將請求提交到本項目中其他文件,還是其它項目,所以需要指定項目名:
<form action="/day17_registerdemo/login" method="post">
用戶名:<input type="text" name="username" /><br />
密 碼:<input type="password" name="password" /><br />
<input type="submit" value="登錄">
</form>