1

I'm trying to write a servlet Filter that under certain conditions will read the HTML response returned by the JSP file and process it (using an XHTML parser) and make some modifications to it before finally returning it to the browser (basically I'm trying to implement a global change to avoid having to modify hundreds of JSPs individually)

I'm using Tomcat. I started out by providing a wrapper for the HttpServletResponse and the ServletOutputStream before passing them back to the filter chain. However, I'm getting an "IllegalStateException: getOutputStream() has already been called for this response." It seems to happen whenever one of our taglibs tries to write using the writer returned by "this.pageContext.getOut()", so I guess the response/writer/outputstream being used by Tomcat isn't using the wrapper classes I passed via the filter.

Any suggestions? Or is there a better way to accomplish what I'm trying to do?

1 Answer 1

1

I think the response is being committed before you pass back the modified XML.

To know the reasons why the response was committed , Look here

If you do not want to get the response committed, you should be doing these two things:

  • Increase the JSP buffer size in page directive

    <%@ page buffer="5kb" autoFlush="false" %>

  • Increase the server default max buffer size.

    ServletRespnse.setBufferSize()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.