gpt4 book ai didi

java - Dispatcher servlet spring 和 url 模式

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:53:06 25 4
gpt4 key购买 nike

我是 spring 框架的新手,今天我遇到了 web.xml 文件中的调度程序 servlet 配置,我想出了一个关于 url 模式的问题,比如这个语法/。那么,如果我按如下方式在 tomcat 服务器中部署 Web 应用程序,“/”符号实际上适用于什么:host:port/或 host:port/myWeb/

最佳答案

模式 / 将使您的 servlet 成为应用程序的默认 servlet,这意味着它将选择没有另一个完全匹配的每个模式。

URL 模式映射:

  • 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.

路径映射规则:

  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.

关于java - Dispatcher servlet spring 和 url 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17360374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com