jQuery in Action, 3rd edition
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Regarding Filters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Regarding Filters" Watch "Regarding Filters" New topic

Regarding Filters

yekkala krishna
Ranch Hand

Joined: Mar 04, 2007
Posts: 105

I am following Hanumant Deshmukh material for preparation of SCWCD Exam.I have small query regarding the following question.Can Anybody expalain the below question?

Question: 3. Given these filter mapping declarations:

in what order are the filters invoked for the following browser request?

a FilterOne, FilterThree
b FilterOne, FilterTwo, FilterThree
c FilterThree, FilterTwo,FilterOne
d FilterThree, FilterTwo
e FilterThree
f None of these filters are invoked.

Answer for above question is d.

Can any body explain how FilterTwo invokes after invocation of FilterThree.

With Regards,
Rama Krishna.Y
Patil Niteen
Ranch Hand

Joined: Dec 10, 2009
Posts: 48

The rules for filter mapping are:

1. All filters with matching url patterns are located first.Filters with matching url patterns are placed in the chain in the order in which they are declared in the DD.
2. Once the filters with the matching url patterns are placed in the chain, the container does the same thing with the filters that have a matching <servlet-name> in the DD.

FilterTwo invokes after invocation of FilterThree.


Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
I would like to know, why Filter1 would not be called. It has a matching URL pattern.

Thanks and Regards
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi, Satya.

If we don't mention <dispatcher> element in <filter-mapping>, or mention it as empty like then it defaults to REQUEST.

Suppose if we send request to the container like, , then container selects the appropriate filters by seeing its <url-parttern> and <dispatcher> element. Here first it sees the 'FilterOne' url-pattern(/admin/*), this is ok, and it sees its <dispatcher> entry, here it is 'FORWARD', it skip this step and moves to the next ones, 'FilterThree' and 'FilterTwo', they satisfy the rules. Finally, it makes a mapping that first I(container) should call 'FilterThree' and after I should call 'FilterTwo'.

Incase if we use RequestDispatcher to forward request to any resource like calling,

then before forwarding to the resource that was present in 'admin' directory, first it checks the <filter-mapping>'s <dispatcher> declaration, like is there is 'FORWARD' present in it? Here it is present. Then it calls the 'FilterOne's doFilter() method and if our doFilter() contains then the resource will be forward to the 'result.jsp'.
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
Thanks Chinmaya
I agree. Here's the link: http://aspose.com/file-tools
subject: Regarding Filters
It's not a secret anymore!