Search code examples
javajakarta-eeservletsservlet-filters

What will be the order in which filters will be called?


Suppose I have following in my web.xml

<filter-mapping>
    <filter-name>F1</filter-name>
    <url-pattern>/XYZ/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>F2</filter-name>
    <url-pattern>/XYZ/abc.do</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>F3</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

What will be the order in which the filters will be called if a request comes as /XYZ/abc.do and why?


Solution

  • In the order their mappings are defined in web.xml

    If using annotations (@WebFilter) the order seems to be undefined - you still have to declare the <filter-mapping> entries in web.xml.