O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Architecture of a response filter

Rachel is talking about the basic structure of what you put in a doFilter() method—first you do work related to the request, then you call chain.doFilter(), then finally, when the servlet (and any other filter in the chain after your filter) completes and control is returned to your original doFilter()method, you can do something to the response.

Rachel’s pseudo-code for the compression filter

image with no caption

The conceptual call stack

The Compression filter’s doFilter() method runs, and invokes chain.doFilter(). It’s too early to do any compression—the goal is to compress the response output from the servlet.

The Servlet’s service() method goes on the top of the stack, does some work, generates a response output, and completes.

Now that the Servlet’s service() method has popped off the stack, the rest of the compression filter’s doFilter() method can run, and (it hopes) do the compression on whatever the servlet wrote to the response output!

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required