ERiK 发表于 2013-2-4 13:59:49

zz: Servlet的Request

<span style="font-family: Arial, sans-serif, Helvetica, Tahoma; line-height: 18px;">Servlet的Request中和用户请求路径相关的操作有多个,下面一一列举:
1.getQueryString(),&之后GET方法的参数部分。
2.getServletPath(),web.xml中定义的Servlet访问路径。
3.getPathInfo(),Servlet访问路径之后,QueryString之前的中间部分。
4.getContextPath(),Context路径前缀(这个应该是最熟悉的啦)。
5.getRequestURI(),等于getContextPath() + getServletPath() + getPathInfo()。
6.getRequestURL(),等于getScheme() + "://" + getServerName() + ":" + getServerPort() + getRequestURI()。
7.getPathTranslated(),等于getServletContext().getRealPath("/") + getPathInfo()。
注意:
1.getServletContext().getRealPath("/") 后包含当前系统的文件夹分隔符(windows系统是"\",linux系统是"/"),而getPathInfo()以"/"开头。
<div class="dp-highlighter" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; font-size: 12px; background-color: transparent; width: 694px; margin-left: 9px; padding: 1px;"><div class="bar"><div class="tools" style="text-align: left; color: black; font-weight: bold; padding: 3px; margin: 0px;">Java代码  http://mlaaalm.iteye.com/images/icon_star.png
页: [1]
查看完整版本: zz: Servlet的Request