Hi All,
Below are the lines taken from Head First
Servlets and
JSP
1 The filter passes the request and response to the servlet, and waits patiently for its chance to compress stuff.
2a The servlet does its thing,creating output, blissfully unaware that this very same output was supposed to be compressed.
2b The output goes back through the Container and...
2c It’s sent back to the client!Hmmm... this could be a problem.The filter was hoping to have a chance to do something to the output (compress it) before the output went to the client.
3 The call to chain.doFilter() has returned, and the filter was hoping to grab the output and and start compressing...
EXCEPT it’s too late! The output was already sent to the client! The Container doesn’t buffer the output for the filter.
By the time the filter’s own doFilter() method is at the top of the (conceptual) stack, it’s too late for the filter to affect the output.
What I didn't understand is the point no. 3 ,where it is said that "The output was already sent to the client".
Let's say we have two filters (FA and FB) and a servlet (SA).Whenever the client requests SA, the container will redirect the request first to FA and then to FB which in turn redirect it to SA (Please correct me in case).And when SA send the response to client it will first pass to FB and then FA and then to client(skeptical).
But according to the book, the response will be sent directly to client by SA but the control will be move from SA to FB and then FA.
Please Explain!!
Thanks