This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Please explain Filter chaining mechanism. On which basis the filters are chained or on what basis the filters are organised in a chain sequence. HFSJ filter chaining whould be a great example to explain. Why the Filter5 is being called at 2nd number in 2nd and 3rd request path
"Know where to find the solution and how to use it - that's the secret of success."
if you have more than one filter matching the requested url pattern in your web.xml then these will be invoked in order as these are defined in DD.
One more thing to add here is that if some filter is defined using <servlet-name> in it then it will be invoked lastly and if these are also multiple matching the same request url then same rule will be applied as above. [ March 19, 2007: Message edited by: Ali Gohar ]
Joined: Nov 14, 2005
Does <url-pattern> play any role in deciding filter sequence in chain.
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 Web resource. � 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. [ March 19, 2007: Message edited by: Satou kurinosuke ]