Forums Register Login

Response objects in a Filter

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
catch it before it slithers away! Oh wait, it's a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 630 times.
Similar Threads
Passed Part One with 87%
Question about servlet filters
Confusion regarding filters (HFSJ)
Passed
Passed!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:00:24.