How can I intercept the output of the JSP engine (before it is delivered to the client), so that I can manipulate it before sending it to the connecting client?

Serge Knystautas

As a design principle in JSP 1.1/Servlet 2.2, there is not a way to do this.

There is a way to do a version of this manipulation, however, using a custom tag library. You can wrap a custom tag around your entire JSP, and then your custom tag can view what was generated by the JSP code and perform any manipulations it wants before sending something on to the browser. Your JSP page might look something like this:

<%@ taglib uri="mytaglib.tld" prefix="custom" %>

My existing JSP.
int i = 0;


In the JSP 1.2/Servlet 2.3 spec (which will not be published in final form until near the end of 2000), there is a new concept of a servlet filter. A servlet filter is a new class that can manipulate the output of a servlet or JSP, exactly as you request. Read the Servlet 2.3 specification to see how this works.