首页 > 代码库 > HttpServletRequest 中 getRequestURL和getRequestURI的区别

HttpServletRequest 中 getRequestURL和getRequestURI的区别

比如说有这样的一个页面

test1.jsp=======================

<a href ="http://www.mamicode.com/test.jsp?name=wf">跳转到test2.jsp</a>

test2.jsp=======================

HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
String servletPath = req.getRequestURI()
String servletPath = req.getRequestURL()

得到的值为:req.getRequestURI()-----> /test/test.jsp 

  req.getRequestURL()-----> http://localhost:8080/test/test.jsp 

 

 

 

 

 

 

 

 

 

 

 

其他方法:

 

basePath :http://localhost:8080/test/

 

getContextPath :/test 
getServletPath :/test.jsp 
getRealPath :D:\Tomcat 6.0\webapps\test\ 
getServletContext().getRealPath :D:\Tomcat 6.0\webapps\test\ 
getQueryString :name=wf

 

HttpServletRequest 中 getRequestURL和getRequestURI的区别