wood burning stoves 2.0*
The moose likes Servlets and the fly likes Servlet Filter chain construction order Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Filter chain construction order" Watch "Servlet Filter chain construction order" New topic
Author

Servlet Filter chain construction order

narain ashwin
Ranch Hand

Joined: Dec 27, 2007
Posts: 48
I am learning servlet filters and while browsing for filter chain construction I have stumbled on this
Thread.

The resolution from the thread is that

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.

According to point # 1 if multiple filters match the requested URL, the filters would be called in the order they are declared in the DD.Assume the DD to contain

then the filter chain for request /Recipes/HopsList.do would be Filter2,Filter1 even though Filter1 is more specific.
I am not understanding point # 2.What does <servlet-name> has to do with filters, if it has how can we specify the servlet in the filter..


I drink two cappuccinos a day.Is that of any help to solve java problems??
JBoss 6 - Admin console Username/pwd: admin/admin
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

<filter-mapping> elements can have child <servlet-name> elements.
narain ashwin
Ranch Hand

Joined: Dec 27, 2007
Posts: 48
Thanks a lot David, it works! Here is a piece of code


The Filter chain is Filter2,Filter1 because of rule # 2, though the order in DD is Filter1,Filter2
 
Don't get me started about those stupid light bulbs.
 
subject: Servlet Filter chain construction order