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.
posted 7 years ago
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.
SCJP 5.0(84%), SCWCD 5.0(97%), SCDJWS 5.0(98%)
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads