I am getting these errors when running a ToolTwist application in production. This seems to happen ofter. What are the possible code errors that could lead to these stack traces?
2012-02-13 11:00:04,242 ERROR ServletUiModule - Error in Servlet tooltwist.ecommerce.RoutingUIM.doPost():
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:312)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
ANSWER A
HttpServlet has two variations for getting the output stream – response.getWriter(), and response.getOutputStream(). In our case we use uh.getResponse() to get the response object.
A few rules –
1. One one of these approaches ca be used.
2. The chosen method cannot be called twice.
3. Once you have the output object, irrespective of whether you got a writer or an output stream, once you close it, you cannot use it again, nor get another one.
In short, writing the servlets output is a one-shot operation. You get the object, you write, your return from the servlet.
ANSWER B
I seem to recall there may also be a situation where you are writing to the output, but then the error handler kicks in to handle an exception, and the error page has a problem creating further output. Any page used to handle errors must specifically have the errorpage tag (i don’t recall exactly the tag).
ANSWER C
Once you have written something to the servlet’s output, you cannot forward to another page without getting this error.