Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Necessity of wrappers for manipulating Servlet Response

 
Fahim Farook
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4678
7
Linux Mac OS X VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic