I haven't done this personally, but I believe it can be done by using filters. The following is some pseudocode.
1) Create a Wrapper class with a method to get output stream
class JSPOutputResponseWrapper extends HttpServeletResponseWrapper {
public ServletOutputStream getOutputStream() throws ... {
}
}
2) Create the filter class. In the class use the JSPOutputResponseWrapper class
public class JSPFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
JSPOutputResponseWrapper wrappedResponse = new JSPOutputResponseWrapper(response)
chain.doFilter(request, wrappedResponse);
// get JSP output and email from here using wrappedResponse
}
}
3) web.xml
<filter>
<filter-name>JSPFilter</filter-name>
<filter-class>com.mycompany.myapp.filter.JSPFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>JSPFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
Let me know what do you think.