aspose 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
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: 4658
    
    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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Necessity of wrappers for manipulating Servlet Response