Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple URL pattern elements in web.xml

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

<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.xsd and the definition looks like this:

  <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:

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.

See image: Eclipse error

like image 824
Ayusman Avatar asked Oct 13 '12 00:10

Ayusman


2 Answers

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>
like image 100
Assen Kolov Avatar answered Dec 04 '22 14:12

Assen Kolov


Default is 1 for maxOccurs and minOccurs in sequence element:
https://msdn.microsoft.com/en-us/library/ms256089(v=vs.110).aspx.

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

like image 28
Aleksandr M Avatar answered Dec 04 '22 15:12

Aleksandr M