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!