一、Servlet中URL的组成
URL组成:URL=ContextPath+ServletPath+PathInfo
假设Servlet中Web.xml配置:
<servlet-mapping>
<servlet-name>ServletName</servlet-name>
<url-pattern>hello</url-pattern>
</servlet-mapping>
假设URL:/Demo/hello/info.view
1、ContextPth(环境路径)
部署程序的程序名作为环境路径,使用HttpServletRequst.getContextPath()获取结果为“/Demo”
2、ServletPath(Servlet路径)
Servlet路径,不包括PathInfo和请求参数,使用HttpServletRequest.getServletPath()获取结果为“/hello”
3、PathInfo(路径信息)
路径信息不包括参数、ContextPath、ServletPath的其他路径部分。使用HttpServletRequest.getPathInfo()获取结果为“info.view”