Servlet filters' order of execution
When the container recives a request, it first finds all the filter mappings with a <url-pattern>
that matches the request URI. This becomes the first set of filters in the filter chain.Next it finds all the filter mappings with a <servlet-name>
that matches the request URI. This becomes the second set of filters in the filter chain.In both the sets the filters are executed in the order in which they are declared in the Deployment descriptor(D.D.)
According to the specs
The order the container uses in building the chain of filters to be applied for a particular request URI is as follows:
- First, the
<url-pattern>
matching filter mappings in the same order that these elements appear in the deployment descriptor.- Next, the
<servlet-name>
matching filter mappings in the same order that these elements appear in the deployment descriptor.