• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filter Chain Order

 
Raef Kandeel
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confused as to the order in which filters are chained. In other words, when the filters appear in the web.xml, how does the container choose the order. Thanks.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know off the top of my head either, but I do know that the servlet specification mandates the order. So you can look it up there.
 
Dan Walin
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what I think I learned - first all those mapped to a url are looked at and then the order they appear in the DD is used, then those mapped to servlets are looked at and the order they appear in the DD is used. Don't take my word for it, I'm testing my memory. You ought to look at the book to be sure. That's what I'm about to do.
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For Filters :
First all <url-pattern> are matched and then <servlet-name>

For example :
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>com.Hello</servlet-class>
</servlet-mapping>

1) <url-pattern>/ab/* </url-pattern>
2) <servlet-name>HelloServlet</servlet-name>
3) <url-pattern>/ab/cd/* </url-pattern>
4) <url-pattern>/ef/* </url-pattern>

Now for the request http://localhost:8080/myapp/ab/sandeep
It chain order will be 1,3,2

This is nicely explained in HFSJ Filters Chapter!!!

Hope this clarifies your doubt!!!
 
Raef Kandeel
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic