Request中getContextPath、getServletPath、getRequestURI、getRequestURL、getRealPath的區別

假定你的web application 名稱爲news,你在瀏覽器中輸入請求路徑:
http://localhost:8080/news/main/list.jsp
則執行下面向行代碼後打印出如下結果:
1、 System.out.println(request.getContextPath());
打印結果:/news
2、System.out.println(request.getServletPath());
打印結果:/main/list.jsp
3、 System.out.println(request.getRequestURI());
打印結果:/news/main/list.jsp
4、System.out.println(request.getRequestURL());
打印結果:http://localhost:8080/news/main/list.jsp
5、 System.out.println(request.getRealPath("/"));
打印結果:F:\Tomcat 6.0\webapps\news\test

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章