兩種url地址:
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://