This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlet Filter Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Servlet Filter" Watch "Servlet Filter" New topic
Author

Servlet Filter

Rajeev Iyer
Ranch Hand

Joined: Jun 19, 2002
Posts: 42
What is a Servlet Filter ?
How and why would one need it ?
Thanks ......
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6919
A servlet filter is a chunk of code that gets executed for every request (or response) that it is mapped to. For example, you might map a filter to all requests for URLs matching /private/* which checks whether the requester has logged in and is authorized to see the resource.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Ken Robinson
Ranch Hand

Joined: Dec 23, 2003
Posts: 101
You can only map a URL to one Servlet.
You can map a URL to multiple Filters.
As stated above, this allows you to place code that is very common in a Filter and map which URLs you want it to apply to. You only write the code once. If you wanted this without Filters, you would have to put the same code or method call in each and every place you wanted and recompile.
Rajeev Iyer
Ranch Hand

Joined: Jun 19, 2002
Posts: 42
Thanks for the replies...
Could you please suggest any site where I can view some example code ?
Thanks....
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Servlet Filter
 
Similar Threads
Redirecting address
Tracking users and user security
mapping a URL to a java class
Redirecting to login.jsp page?
where to validate a LOGIN ?