Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

servlet filter  RSS feed

 
anita dhar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the use of servlet filter and where we are using practically
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
the question is rather generic. You may use it for:
1. Authentication
2. Logging
3. Dispatching
4. Decorating (see HttpServlet<Request|Response>Wrapper
5. ...
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anitha,

"Filter" - as the term indicates it is to filter out ! It could be of anything which interests to you. Filters are basically introduced to have some customization before the original request is being passed to the Servlet.

Say for example, you may think of authenticating the User before passing it on the request to the actual servlet which will be fetching the data which the user is allowed to see in a web application. In such case, you may not want to overload the actual servlet doing it.

Instead, you introduce a middle layer - which is nothing but a filter - which jumps in and does your job and then it directs the control with the request object to the actual servlet. You may call it as "Authentication Filter".

Filters can be chained in such a way that once a filter is done, it can invoke another filter by passing on the modified request object till then.

The same way filters can be used for doing some customization on the response object - say zipping the content of output, checking the filetype etc.



Some of these links might help you to know more.

  • Essentials of Filter
  • Filter Code with Servlet 2.3 Model
  • Writing Servlet Filters
  • Two Servlet Filters every web application should have



  • HtH.

    [ May 24, 2007: Message edited by: Raghavan Muthu ]
    [ May 24, 2007: Message edited by: Raghavan Muthu ]
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!