码迷,mamicode.com
首页 > Web开发 > 详细

getRequestURI()与getRequestURL()的区别

时间:2017-05-05 21:46:45      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:translate   targe   .com   system   local   roo   std   cto   nec   

引于: http://hi.baidu.com/cloudxpc

request.getRequestURI() 返回值类似:/xuejava/requestdemo.jsp

request.getRequestURL() 返回值类似:http://localhost:8080/xuejava/requestdemo.jsp

 

附:

request.getContextPath() = /hboys
request.getLocalAddr() = 127.0.0.1
request.getPathInfo() = null
request.getPathTranslated() = null
request.getRemoteAddr() = 127.0.0.1
request.getRequestURI() = /hboys/
request.getScheme() = http
request.getServerName() = 127.0.0.1
request.getServletPath() = /index.jsp
request.getClass() = class org.apache.catalina.connector.RequestFacade
request.getHeaderNames() = 
request.getLocale() = zh_CN
request.getLocales() = 
request.getParameterMap() = {}
request.getRequestURL() = http://127.0.0.1:8081/hboys/
request.getUserPrincipal() = null
request.getParameterNames() = 
request.getRealPath("newsPub") = D:\workspace\hboys\WebRoot\newsPub

 

假定你的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.getRealPath("/"));

打印结果:F:\Tomcat 6.0\webapps\news\test

getRequestURI()与getRequestURL()的区别

标签:translate   targe   .com   system   local   roo   std   cto   nec   

原文地址:http://www.cnblogs.com/genhao/p/6814969.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!