首页
学习
活动
专区
圈层
工具
发布

SpringFramework之Servlet的request path

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

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

                                                   图1 HttpServletRequest接口的方法

1.Request path的组成

    requestURI = contextPath + servletPath + pathInfo

    HttpServletRequest接口有以下几个方法

  1. getContextPath
  2. getServletPath
  3. getPathInfo

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

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

    从图2中可以看出,ContextPath基本是固定的,而ServletPath取决于我们在web.xml的servlet-mapping中的url-pattern值。

(adsbygoogle = window.adsbygoogle || []).push({});

下一篇
举报
领券