Web.xml:url模式标记是否彼此相对? [英] Web.xml: Are url-pattern tags relative to each other?

查看:112
本文介绍了Web.xml:url模式标记是否彼此相对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   <servlet-mapping>
      <servlet-name>myName</servlet-name>
      <url-pattern>/aName</url-pattern>
   </servlet-mapping>

    <security-constraint>

            <web-resource-collection>

                    ...

                    <url-pattern>
                            /*
                    </url-pattern>

            </web-resource-collection>

             ...

    </security-constraint>

这是web.xml的摘录(使用它来配置jboss/tomcat Web服务).只是想知道web-resource-collection中的url-pattern是否相对于servlet-mapping中的url-pattern.

This is an excerpt from web.xml (using it to configure a jboss/tomcat webservice). Just wondering if the url-pattern in web-resource-collection is relative to the url-pattern in servlet-mapping.

推荐答案

用于为给定请求选择约束的url-pattern与任何事物都不相关. Servlet规范中有趣的部分是:

The url-pattern used to select the constraints for a given request are not relative to anything. The interesting parts of the Servlet spec here are:

SRV.12.8.3处理请求

当Servlet容器收到一个 请求,它应该使用算法 SRV.11.1中描述的选择 约束(如果有)在 url-pattern是最匹配的 请求URI.如果没有约束 选择后,容器应接受 请求.否则容器 应当确定HTTP方法是否 该请求被限制在 选定的模式.如果不是,则 要求将被接受.否则, 该请求必须满足 适用于http-method的约束 在url-pattern.两者 必须满足以下规则 被接受的请求,以及 分派到关联的servlet.

SRV.12.8.3 Processing Requests

When a Servlet container receives a request, it shall use the algorithm described in SRV.11.1 to select the constraints (if any) defined on the url-pattern that is the best match to the request URI. If no constraints are selected, the container shall accept the request. Otherwise the container shall determine if the HTTP method of the request is constrained at the selected pattern. If it is not, the request shall be accepted. Otherwise, the request must satisfy the constraints that apply to the http-method at the url-pattern. Both of the following rules must be satisfied for the request to be accepted and dispatched to the associated servlet.

并且:

SRV.11.1 URL路径的使用

在收到客户请求后,Web容器确定Web应用程序 向其转发.所选的Web应用程序必须具有最长的 与请求URL的开头相匹配的上下文路径.网址的匹配部分 是映射到servlet时的上下文路径.

SRV.11.1 Use of URL Paths

Upon receipt of a client request, the Web container determines the Web application to which to forward it. The Web application selected must have the longest context path that matches the start of the request URL. The matched part of the URL is the context path when mapping to servlets.

Web容器接下来必须找到servlet来使用处理请求 路径映射过程如下所述..

The Web container next must locate the servlet to process the request using the path mapping procedure described below.

用于映射到servlet的路径是来自请求的请求URL 对象减去上下文路径和路径参数. URL路径映射 以下规则是按顺序使用的.成功使用第一个成功的比赛 尝试匹配:

The path used for mapping to a servlet is the request URL from the request object minus the context path and the path parameters. The URL path mapping rules below are used in order. The first successful match is used with no further matches attempted:

  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 ’.’ char- acter.
  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.

SRV.11.2映射规范

在Web应用程序部署描述符中,以下语法用于定义 映射:

SRV.11.2 Specification of Mappings

In the Web application deployment descriptor, the following syntax is used to define mappings:

  • 使用以'/'字符开头并以'/*'后缀结尾的字符串 用于路径映射.
  • 以'*.'前缀开头的字符串用作扩展名映射.
  • 仅包含"/"字符的字符串表示 应用程序.在这种情况下,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.

这篇关于Web.xml:url模式标记是否彼此相对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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