eclipse web.xml 中的多个 URL 模式元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12868689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 19:11:27  来源:igfitidea点击:

Multiple URL pattern elements in web.xml

eclipsejakarta-eeweb.xml

提问by Ayusman

Is it OK to have multiple elements in the element in a J2EE web app version 2.4 compliant web.xml like this:

在 J2EE Web 应用程序版本 2.4 兼容的 web.xml 中的元素中是否可以有多个元素,如下所示:

<filter-mapping>
    <filter-name>SomeFilter</filter-name>
    <url-pattern>*.htm</url-pattern>
    <url-pattern>*.do</url-pattern>
</filter-mapping>

I looked up the XSD "web-app_2_4.xsd" file from here : http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsdand the definition looks like this:

我从这里查找了 XSD“web-app_2_4.xsd”文件:http: //java.sun.com/xml/ns/j2ee/web-app_2_4.xsd,定义如下:

  <xsd:complexType name="filter-mappingType">
    <xsd:annotation>
      <xsd:documentation>
            some documentation here
      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:element name="filter-name"
           type="j2ee:filter-nameType"/>
      <xsd:choice>
    <xsd:element name="url-pattern"
             type="j2ee:url-patternType"/>
    <xsd:element name="servlet-name"
             type="j2ee:servlet-nameType"/>
      </xsd:choice>
      <xsd:element name="dispatcher"
           type="j2ee:dispatcherType"
           minOccurs="0" maxOccurs="4"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

The URL pattern definition looks like this:

URL 模式定义如下所示:

So I think, we can have multiple elements in the element. My Eclipse IDE however does not seem to agree with me, and expects a 'dispatcher' tag.

所以我认为,我们可以在元素中有多个元素。然而,我的 Eclipse IDE 似乎不同意我的看法,并期望有一个“调度员”标签。

See image: Eclipse error

见图片: 日食错误

采纳答案by Aleksandr M

Default is 1for maxOccursand minOccursin sequenceelement:
https://msdn.microsoft.com/en-us/library/ms256089(v=vs.110).aspx.

默认值是1maxOccursminOccurssequence元素:
https://msdn.microsoft.com/en-us/library/ms256089(v=vs.110).aspx

And choiceallows only one of the elements of it:
https://msdn.microsoft.com/en-us/library/ms256109(v=vs.110).aspx

并且choice只允许它的一个元素:https:
//msdn.microsoft.com/en-us/library/ms256109(v=vs.110).aspx

回答by Assen Kolov

Clearly no, but you can have:

显然不,但你可以:

<filter-mapping>
 <filter-name>SomeFilter</filter-name>
 <url-pattern>*.htm</url-pattern>
</filter-mapping>    

<filter-mapping>
 <filter-name>SomeFilter</filter-name>
 <url-pattern>*.do</url-pattern>
</filter-mapping>