SpringFramework之Servlet的request path

    注:在阅读下文前,建议先去阅读JCP的Servlet规范。web

    先上一张图,以下图1所示,HttpServletRequest继承自ServletRequest接口。app

                                  

                                                   图1 HttpServletRequest接口的方法url

 

1.Request path的组成

    requestURI = contextPath + servletPath + pathInfospa

    HttpServletRequest接口有如下几个方法xml

  1. getContextPath
  2. getServletPath
  3. getPathInfo

 

    以下图2中的例子,说明了哪些是ContextPath,哪些是ServletPath,哪些是PathInfo。blog

                                                         图2 从Servlet规范中截取的例子继承

    从图2中能够看出,ContextPath基本是固定的,而ServletPath取决于咱们在web.xml的servlet-mapping中的url-pattern值。接口

相关文章
相关标签/搜索