Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletFilters

 
Sree kanth
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
Where do i use servlet filters?
When i invoke a servlet filter, does it start a thread(like servlets)?
Rgds,
Sree
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64970
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rajesh Agarwal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear and Ragesh
ThankU
Could you please give me an example?
thx in advance
Rgds
Sree
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64970
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou verymuch
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic