Am 2012-11-28 21:39, schrieb Mark Thomas:
On 28/11/2012 20:34, Michael-O wrote:
Hi,

I am having again trouble with the respone.sendError method. The docs
say that an IllegalStateException is thrown if response has already been
committed. So this should cause an exception:

protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
   PrintWriter out = response.getWriter();
   out.println("ERROR");
   out.flush();
   response.sendError(404);
}

The exception is thrown out to the console but the response is still
written. If I leave out the flush (which commits the response). The
error page comes up.

Is this undefined behavior or some missing code path to transform the
ISE to a HTTP 500 error response?

Nope. Think about it. Once the response has been committed the response
status line and the headers have been written to the client as well as
at least some if not all of the response body. Tomcat can't take back
the data it has already sent.

Sigh, I forgot that the body has already been sent over the wire. Your explanation makes perfectly sense then. sendError is coming too late.

I'd prefer that this ISE would have a message. The source contains a commented exception message.

Thanks,

Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to