且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Dispatcher servlet spring和url模式

更新时间:2023-12-04 11:35:10

模式 / 将使您的servlet成为应用程序的默认servlet,这意味着它将获取每个没有其他完全匹配的模式。

The pattern / will make your servlet the default servlet for the app, meaning it will pick up every pattern that doesn't have another exact match.



  • A以/字符开头并以 / * 后缀结尾的字符串用于路径映射。

  • 以 *。前缀用作扩展名映射。

  • 仅包含 / 的字符串>字符表示应用程序的默认 servlet。在这种情况下,servlet路径是请求URI减去上下文路径,路径信息是 null

  • 使用所有其他字符串仅限完全匹配。

  • A string beginning with a / character and ending with a /* suffix is used for path mapping.
  • A string beginning with a *. prefix is used as an extension mapping.
  • A string containing only the / character indicates the default servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.
  • All other strings are used for exact matches only.



路径映射规则:



Rules for path mapping :



  1. 容器将尝试查找请求路径与servlet路径的完全匹配。成功匹配选择servlet。

  2. 容器将递归尝试匹配最长的路径前缀。这是通过使用 / 字符作为路径分隔符一次单击目录的路径树来完成的。最长匹配确定所选的servlet。

  3. 如果URL路径中的最后一个段包含扩展名(例如 .jsp ),则servlet容器将尝试匹配处理扩展请求的servlet。扩展名定义为最后一个字符后的最后一个部分的一部分。

  4. 如果前三个规则都没有导致在servlet匹配时,容器将尝试提供适合所请求资源的内容。如果为应用程序定义了默认 servlet,则会使用它。

  1. The container will try to find an exact match of the path of the request to the path of the servlet. A successful match selects the servlet.
  2. The container will recursively try to match the longest path-prefix. This is done by stepping down the path tree a directory at a time, using the / character as a path separator. The longest match determines the servlet selected.
  3. If the last segment in the URL path contains an extension (e.g. .jsp), the servlet container will try to match a servlet that handles requests for the extension. An extension is defined as the part of the last segment after the last . character.
  4. If neither of the previous three rules result in a servlet match, the container will attempt to serve content appropriate for the resource requested. If a default servlet is defined for the application, it will be used.