Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about Filter

 
Victor Maehira
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good afternoon ranchers!
I was solving a mock then the following statement appeared: "Filters are called in the order they appear in the deployment descriptor". It was considered true. However, if a filter that has a matching <servlet-name> is declared before a filter with a matching URL pattern, the order is inversed! What do you think?!
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Victor,

"Filters are called in the order they appear in the deployment descriptor".


The above statement is perfectly OK
The only thing is that first the container checks for the url-pattern in the order in which they are are defined in the DD.
And then comes the turn of servlet-name.
<url-pattern> gets preference over <servlet-name>.

But the order of execution is determined by the deployment descriptor. That's true.

Regards,
Khushhal
 
Victor Maehira
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi yadav
I see your point of view. I would say that the statement is partially true! Because it is not the only rule for ordering filter! If a "<servlet-name> filter" is declared before a "<url-pattern> filter", the statement is not true! I know there are more important questions for us to worry about, however we can face similar subtle situations!

[ August 31, 2007: Message edited by: Victor Maehira ]
[ August 31, 2007: Message edited by: Victor Maehira ]
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Victor

But that's only how it works.
There are no more intricacies in it.
Conainer works like this only

The order the container uses in building the chain of filters to be applied for a particular request URI are 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.

Regards,
Khushhal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic