• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Filter chain construction order

 
narain ashwin
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<filter-mapping> elements can have child <servlet-name> elements.
 
narain ashwin
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic