Eclipse – Multiple URL pattern elements in web.xml

eclipsejakarta-eeweb.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

Best Answer

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>
Related Topic