• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Filters

 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to know why we are using filter. Just give a short brief and if possible provide me a good link on topics of filter for beginners.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Filters allow you to intercept and modify the request going to and the response coming from a servlet/JSP. If say all your servlets need to have some kind of pre-processing, validation, or so. You can use filters to modify the request before it reaches your servlets. Hence, all your servlets can share this common functionality.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is something from its vendors The Essentials of Filters.
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlet filters ensure that any accesses to page resources (servlets/jsp/html/jpg/...) go first through the filter and then to the resource, and back out via the filter. This allows you to have one place to handle such things as compression, login, caching, and monitoring.

This site has more about servlet filters as well as a number of examples:
http://wiki.java.net/bin/view/Javapedia/ServletFilter

I have created a servlet filter that tracks performance of all pages. You can see a live demo at http://www.fdsapi.com and read about it at http://www.jamonapi.com. You can get it working in about 5 minutes without making coding changes to your application.
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Filters bring a Decorator pattern in most cases. However you should use filters wisely. Having too many filters can complicate maintenance system and generate unexpected behavior. For example some filter in chain decide to finish request processing and other important filters didn't get called at all.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a nice set of links about filters and examples of them. Check out my link to jamon below to find a servlet filter that monitors application performance.

http://wiki.java.net/bin/view/Javapedia/ServletFilter
 
reply
    Bookmark Topic Watch Topic
  • New Topic