Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Response objects in a Filter  RSS feed

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.
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
I knew I would regret that burrito. But this tiny ad has never caused regrets:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!