简体   繁体   English

Tomcat中的前导斜杠是什么意思 <url-pattern> ?

[英]What is the meaning of the leading slash / in Tomcat's <url-pattern>?

I know I cannot use regular expressions for the <url-pattern> of a filter-mapping, but is it possible to use a directory pattern to specify any url containing the word myuniqws as in: 我知道我不能对过滤器映射的<url-pattern>使用正则表达式,但是可以使用目录模式来指定任何包含单词myuniqws url,如下所示:

https://my.hostname.org/myuniqws/myport/soap?wsdl

I am thinking of perhaps this would be the correct syntax: 我在想这也许是正确的语法:

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

but I have not been able to find documentation for the exact rule of Tomcat's <url-pattern> syntax. 但是我无法找到有关Tomcat <url-pattern>语法的确切规则的文档。

Will the above regex work as I desire? 上述正则表达式是否可以按我的意愿工作?


Update: 更新:

Thanks to the answer below, I discovered the following section in the Java Servlet Specification, which basically answers my questions. 感谢下面的回答,我发现了Java Servlet规范的以下部分,该部分基本上回答了我的问题。

12.2 Specification of Mappings 12.2映射规范

In the Web application deployment descriptor, the following syntax is used to define mappings: 在Web应用程序部署描述符中,以下语法用于定义映射:

  • 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. 前缀用作扩展名映射。
  • The empty string ("") is a special URL pattern that exactly maps to the application's context root, ie, requests of the form http://host:port/<contextroot>/ . 空字符串(“”)是一种特殊的URL模式,它精确地映射到应用程序的上下文根,即,形式为http://host:port/<contextroot>/ In this case the path info is '/' and the servlet path and context path is empty string (““). 在这种情况下,路径信息为“ /”,而servlet路径和上下文路径为空字符串(“”)。
  • A string containing only the '/' character indicates the "default" servlet of the application. 仅包含“ /”字符的字符串表示应用程序的“默认” servlet。 In this case the servlet path is the request URI minus the context path and the path info is null. 在这种情况下,Servlet路径是请求URI减去上下文路径,并且路径信息为null。
  • All other strings are used for exact matches only. 所有其他字符串仅用于完全匹配。

If the effective web.xml (after merging information from fragments and annotations) contains any url-patterns that are mapped to multiple servlets then the deployment must fail. 如果有效的web.xml (合并来自片段和批注的信息之后)包含映射到多个servlet的任何url模式,则部署必须失败。

Presumably, you mean the <url-pattern> for filter mappings in web.xml . 大概是指web.xml过滤器映射的<url-pattern> You might not know this, but web.xml is defined as part of the Java Servlet Specification. 您可能不知道这一点,但是web.xml被定义为Java Servlet规范的一部分。 You can find full documentation for the 3.1 version (currently, the latest and greatest) here: 您可以在以下位置找到有关3.1版的完整文档(当前,最新和最好的):

https://jcp.org/aboutJava/communityprocess/final/jsr340/index.html https://jcp.org/aboutJava/communityprocess/final/jsr340/index.html

If you read section 12.2 ("Specification of Mappings") you can see exactly what kinds of patterns are recognized, including the prefix-mapping you are requesting above. 如果您阅读了第12.2节(“映射的规范”),则可以确切地看到可以识别哪些类型的模式,包括您在上面请求的前缀映射。

EDIT 2014-11-04 : You should know that CATALINA_HOME/conf/web.xml (or CATALINA_BASE/conf/web.xml if you have one) is the default configuration for all web applications deployed on Tomcat and that your webapp's WEB-INF/web.xml is the configuration specific for your own web application. 编辑2014-11-04 :您应该知道CATALINA_HOME/conf/web.xml (如果有的话,也可以是CATALINA_BASE/conf/web.xml )是在Tomcat上部署的所有Web应用程序的默认配置,并且您的WEB-INF/web.xml应用程序是WEB-INF/web.xml是特定于您自己的Web应用程序的配置。 Both of these files should have the following xmlns statements and therefore indicate to you (by their URIs) that they are covered by the Java Servlet Specification (or at least Java EE, which includes the servlet spec): 这两个文件都应具有以下xmlns语句,因此(通过它们的URI)向您表明它们已被Java Servlet规范(或至少包括Servlet规范的Java EE)所涵盖:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM