Filters are invoked in the order of their registration BUT is it not wrong to
say that filter are called in the order they appear in th DD ( bec' filters with <url-pattern>
are invoked before filter with <servlet-name>) ?
It is a bit more subtle: if there are let's say two filters defined on the same servlet: then they will be invoked in the same order of how they are ordered in the deployment descriptor (web.xml). But that requirement comes after the fact of <url-pattern> before <servlet-name>
See the servlet spec explanation:
SRV.6.2.4 Configuration of Filters in a Web Application The order the container uses in building the chain of filters to be applied for a particular request URI is as follows:
1. First, the <url-pattern> matching filter mappings in the same order that these elements appear in the deployment descriptor.
2. Next, the <servlet-name> matching filter mappings in the same order that these elements appear in the deployment descriptor.
This requirement means that the container, when receiving an incoming request, processes the request as follows: - Identifies the target Web resource according to the rules of "Specification of Mappings" on page 86.
- If there are filters matched by servlet name and the Web resource has a
<servlet-name>, the container builds the chain of filters matching in the order
declared in the deployment descriptor. The last filter in this chain corresponds
to the last <servlet-name> matching filter and is the filter that invokes the target
- If there are filters using <url-pattern> matching and the <url-pattern>
matches the request URI according to the rules of Section SRV.11.2, "Specification
of Mappings", the container builds the chain of <url-pattern> matched
filters in the same order as declared in the deployment descriptor. The last filter
in this chain is the last <url-pattern> matching filter in the deployment descriptor
for this request URI. The last filter in this chain is the filter that invokes
the first filter in the <servlet-name> matching chain, or invokes the target Web
resource if there are none.
Joined: Jan 09, 2010
But the problem is I found a the foll Q in M.Green-
Filters are called in the order they appear in the DD.
Simran, that option in Marcus' exam is ambiguous. Filters are called in the order they appear in web.xml but its like a two time pass. First filters are invoked based on url-pattern and then servlet-name. So for the real exam the statement would be false...