javaweb项目中绝对路径的写法理解

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>
posted @ 2017-12-21 11:15  gdwkong  阅读(3857)  评论(0编辑  收藏  举报