首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

HttpServletRe中getContextPath、getServletPath、getRequestURI、request.getRealPath的差异

2012-10-11 
HttpServletRe中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别假定你的WebAppl

HttpServletRe中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别

假定你的WebApplication 名称为swcrm,你在浏览器中输入请求路径:

http://localhost:8080/swcrm/admin/show.jsp
则执行下面向行代码后打印出如下结果:

1、 System.out.println(request.getContextPath());
打印结果:/swcrm
? 2、System.out.println(request.getServletPath());
打印结果:/admin/show.jsp

3、 System.out.println(request.getRequestURI());
打印结果:/swcrm/admin/show.jsp

4、 System.out.println(request.getRealPath("/"));
打印结果:F:\Tomcat 6.0\webapps\swcrm\

?

J2EE api中文版? http://doc.java.sun.com/DocWeb/

热点排行