Necessity of wrappers for manipulating Servlet Response
posted 3 years ago
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.
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.