Dispatcher servlet spring和url模式 [英] Dispatcher servlet spring and url pattern

查看:121
本文介绍了Dispatcher servlet spring和url模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm new to spring framework I today I ran into dispatcher servlet configuration in web.xml file and i came up with a question concerning url pattern like this syntax /. So what does actually the "/" symbol apply in case I deploy web application in tomcat server as following: host:port/ or host:port/myWeb/

推荐答案

模式 / 将使您的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以/字符开头并以 / * 后缀结尾的字符串用于路径映射。

  • 以<$开头的字符串c $ c> *。前缀用作扩展名映射。

  • 仅包含 / 字符表示应用程序的默认 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.


这篇关于Dispatcher servlet spring和url模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆