• Post Reply Bookmark Topic Watch Topic
  • New Topic

Filters

 
Mark Henryson
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • 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.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • 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.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is something from its vendors The Essentials of Filters.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • 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.
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!