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

Compressing output with a response-side filter

Earlier we showed a very simple request filter. But now we’ll look at a response filter. Response filters are a bit trickier, but they can be incredibly useful. They let us do something to the response output after the servlet does its thing, but before the response is sent to the client. So instead of stepping in at the beginning—before the servlet gets the request—we step in at the end—after the servlet gets the request and generates a response.

Well, sort of... think about it. Filters are always invoked in the chain before the servlet. There’s no such thing as a filter that is invoked only after the servlet. But... remember that stack picture. The filter gets another shot at this after the servlet completes its work and is popped off the (virtual) stack!

image with no caption

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