相对路径:
以当前路径开始
- 以
.
开头路径,
./html/a.html
- 直接路径开头(
./
可以省略)
html/a.html
./
:当前目录../
:当前目录的父目录
绝对路径:
以根路径开始
- 以 / 开头的路径
/login_it/login.html
- 完整的路径
http://localhost:8080/login_it/login.html
- / :根目录
javaweb的路径组成
对于给客户端浏览器使用的路径 路径组成如下
总结
路径给客户端浏览器使用:需要虚拟目录(项目的访问路径)
虚拟目录动态获取: request.getContextPath()
例如
- <a>标签
<a href="/login_it/login.html">返回登录</a>
- <form>表单
<form action="/login_it/LoginServlet" method="post">
- sendredirect重定向
response.sendRedirect("/login_it/login.html");
对于给服务器使用的路径,路径组成如下
总结
路径给服务器使用:不需要加虚拟目录
例如:
- forword转发路径
req.getRequestDispatcher("/SuccessServlet").forward(req,resp);
tips
虚拟目录的设置