Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Response objects in a Filter

 
Giri Thava
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the first few chapters of the book it is explained that
the response object that is passed into the servlet is also
used to write the output to client. But in the Filters chapter
it seems the response object that is passed into chain.doFilter()
is not used to write the output, instead a new response object
is used. I mean, two different response objects are used before and
after the call to chain.doFilter().

I like to make it clear whether this is the actual scenario?

Thanks in advance.
 
udaykumar maddigatla
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI

The main purpose of the response object is to send some data to the client.

Filters are used to do some pre or post processing on request and response objects.(There are few other usages where we can use filters).

Filter.doFilter will accept request and response objects as you know.

Assume one scenario which is given in HFSJ book. If you want to do something to the request object before it handed to servlet(or jsp), take that object and wrap it and send the wrapper request to the servlet(or jsp).

Same as the case of Response. I fyou want to add some headers or edit some thing on response object, before it send it to the client . Use wrapper of Response object.

Remember that Filter.doFilter will accpet any kind of request and response objects.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic