Tomcat HttpServletRequest中几个解析URL的函数

在Servlet处理URL请求的路径时,HTTPServletRequest有如下几个常用的函数:

网上的一个小结,Servlet的匹配路径为/test%3F/*,并且Web应用是部署在/app下,此时请求的URL为http://30thh.loc:8480/app/test%3F/a%3F+b;jsessionid=s%3F+ID?p+1=c+d&p+2=e+f#a,各个函数解析如下表:

函数 URL解码 解析结构


getRequestURL() no http://30thh.loc:8480/app/test%3F/a%3F+b;jsessionid=s%3F+ID getRequestURI() no /app/test%3F/a%3F+b;jsessionid=s%3F+ID getContextPath() no /app getServletPath() yes /test? getPathInfo() yes /a?+b