This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Servlets and the fly likes ServletFilters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "ServletFilters" Watch "ServletFilters" New topic
Author

ServletFilters

Sree kanth
Ranch Hand

Joined: Feb 02, 2005
Posts: 53
Hi all
Where do i use servlet filters?
When i invoke a servlet filter, does it start a thread(like servlets)?
Rgds,
Sree


Sree
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

You would use filter whenever you want to preview or post-view a request/response cycle.

A filter runs in the same thread as the servlet (or other resource) that is being filtered.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rajesh Agarwal
Ranch Hand

Joined: Aug 01, 2005
Posts: 79
Too many threads about Filters are floating around. Can we have 1 thread which explains the basic use and with an example, where a request/response is modified. I know several books would list that, but considering the fact that the owner of the thread would come here only after going through all that.

Not sure if such a thread already exists. If not... then why not this one.
Whenever there is a question on Filters, we could direct them to this one.

Agree... disagree?
Sree kanth
Ranch Hand

Joined: Feb 02, 2005
Posts: 53
Hi Bear and Ragesh
ThankU
Could you please give me an example?
thx in advance
Rgds
Sree
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

Originally posted by Sree kanth:

Could you please give me an example?


One way I use filters is for authentication. When an internal controller of the web app is requested, a filter checks to make sure that an authentication token is in the session. if so, the request is allowed to proceeed normally. Otherwise, the filter forwards to the login mechanism.
Sree kanth
Ranch Hand

Joined: Feb 02, 2005
Posts: 53
Thankyou verymuch
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Moreover, we mostly use filter in order to perform some tasks mention below.

- Authentication of requests
- Data encryption
- Data compression
- Logging
- Extensible Stylesheet Language Transformation (XSLT) filtering
- Image conversion
- etc.

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ServletFilters