1. "/"给服务器使用, 代表web工程根路径(webroot)
2. "/"给浏览器使用, 代表tomcat 目录下的webapps文件夹

注意:

1. 开发中一般不使用绝对地址
2. 开发中只要是写url地址, 都以/开头

举例:

 1 // servletcontext
 2 this.getServletContext().getRealPath("/image/apple.png"); // 服务器
 3 
 4 // forward 转发
 5 this.getServletContext().getRequestDispatcher("/register.html"); // 服务器
 6 
 7 // sendRedirect 重定向
 8 response.sendRedirect("/burgundyred/register.html"); // 浏览器
 9 
10 // 页面超链接
11 <a href="/burgundyred/servlet/Demo.do">点击</a> // 浏览器
12 <a href="${pageContext.request.contextPath }/servlet/Demo.do">点击</a> 

 

拓展: 使用//还是\\?

1. 读取url资源使用// 

e.g. C:\\abd\\asd


2. 读取硬盘上的资源使用\\ 

e.g. http://

相关文章:

  • 2021-08-04
  • 2022-01-05
  • 2022-12-23
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-21
  • 2021-10-23
  • 2022-12-23
相关资源
相似解决方案