相对路径,绝对路径,以及javaweb的路径的组成 / ./ ../的区别

相对路径:

以当前路径开始

  1. .开头路径,
    ./html/a.html
  2. 直接路径开头(./可以省略)
    html/a.html
  • ./:当前目录
  • ../:当前目录的父目录

绝对路径:

以根路径开始

  1. 以 / 开头的路径
    /login_it/login.html
  2. 完整的路径
    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

虚拟目录的设置在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/ren9436/article/details/107992961