File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Necessity of wrappers for manipulating Servlet Response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Necessity of wrappers for manipulating Servlet Response" Watch "Necessity of wrappers for manipulating Servlet Response" New topic
Author

Necessity of wrappers for manipulating Servlet Response

Fahim Farook
Greenhorn

Joined: Mar 20, 2011
Posts: 12
I'm new to Servlet Filters and I read HF Servlets and JSPs. But one questions I have is why can't a Filter manipulate an HttpServletsResponse after calling its chain.doFilter() without having it wrapped. Theoritically once chain.doFilter() completes we still have a reference to original Request and Response. So why it is too late to do something with the response.

I did some testing like this. From Servlet


And from Filter, after chain.doFilter()


and I got both printed on the JSP. Please explain.

However if from Servlet,


I can't manipulate the response from Filter. Why is that? Please explain.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

The response from the lower level routine may have caused the buffer of data to be sent to the user's browser. Once that happens, its gone, too late to do anything. The bad news is that its essentially impossible to know when the response will be sent out. You can never rely that you can handle it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Necessity of wrappers for manipulating Servlet Response