• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filters,FilterChain

 
kathir vel
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Actually calling fc.doFilter()inside doFilter() will call all filters in FilterChain one by one,then atlast it will pass the req,res to servlet or jsp.
Inside doFilter() method,what will happen if we don't include fc.doFilter()?In HFSJ book it is called as blocking the request processing.What is it mean?Can anyone please explain?Thanks.
 
Tarun Yadav
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It simply means that the request will not be given to the next resource in the chain. You block the request from moving further.

Consider that you have a filter for authorization. It check whether the current request is from a user who is allowed to perform an action. If yes, then it'll simply call FilterChain.doFilter(). If not, the simplest thing would be to not call it. This would give the user a 'blank' response and he/ she will see a blank page in the browser.

Of course, a better and more user-friendly thing to do would be to redirect to an appropriate page and display a message indicating that the user is not allowed to access that resource or perform that action.

Consider it analogous to a method call in an if block; if the condition mathches, call the method and use it. If not, then don't call the method. Everything is the same except that whatever the method was supposed to do is now not done.
 
kathir vel
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Tarun.I got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic