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

Xyzxyz Xyz picture Xyzxyz Xyz · Oct 29, 2011 · Viewed 29.3k times · Source

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?

Answer

Bozho picture Bozho · Oct 29, 2011

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.