HttpServletRequest几个常用方法的区别

Demo

http请求http://localhost:8080/examples/1.jsp?a=11&b=22

Jsp测试代码

<%
         
         out.println("\t     ContextPath: " + request.getContextPath()+"<br/>"); 
         out.println("\t     ServletPath: " + request.getServletPath()+"<br/>"); 
            out.println("\t        PathInfo: " + request.getPathInfo()+"<br/>");
            out.println("\t        RealPath: "+request.getRealPath("/")+"<br/>"); 
            out.println("\t      RequestURI: " + request.getRequestURI()+"<br/>");
            out.println("\t     QueryString: " + request.getQueryString()+"<br/>");
%>

测试结果

ContextPath: /examples
ServletPath: /1.jsp
PathInfo: null //no extra path information
RealPath: D:\soft\tomcat-7.0.23\webapps\examples\
RequestURI: /examples/1.jsp
QueryString: null



原文地址:https://www.cnblogs.com/yangjun1120/p/2730774.html