HttpServletRequest 中 getRequestURL和getRequestURI的区别

时间:2022-07-10 17:04:20

比如说有这样的一个页面

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

<a href ="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