Hi,
I hope this is the correct group.
How should a HttpServlet include custom errors in in AJAX response.
I need to be able to control some client side behaviour based on the
error returned.
I have tried using cuctom status codes in the
HttpServletResponse.setStatus() and sendError() methods but I always
receieve a Status 500 such as in response below.
If an exception is thrown by the servlet a Status 500 is also
returned.
Thanks in advance.
===========================================
responseText = Error 500: null ErrorMessage
Error 500: Server caught unhandled exception from servlet
[testServlet]: ERROR: Cannot set header. Response
already committed.
responseXML.xml =
status = 500
statusText = Internal Server Error
Silvio Bierman - 13 Feb 2007 16:35 GMT
> Hi,
>
[quoted text clipped - 21 lines]
> status = 500
> statusText = Internal Server Error
At the time the exception occurs you have already written to the response.
Therefore, a response header can not be written.
The simplest but not neccesarily most efficient way to handle this is
generate the response to a seperate buffer
(StringWriter/ByteArrayOutputStream will do) and write that out at once if
no errrors occur or just set the error status if one does occur.
Regards,
Silvio Bierman