How to handle exceptions from an image-generating Servlet?

Posted by ssahmed555 on Stack Overflow See other posts from Stack Overflow or by ssahmed555
Published on 2010-05-17T18:42:07Z Indexed on 2010/05/17 18:50 UTC
Read the original article Hit count: 137

Filed under:
|
|

I have a simple (Servlet, JSP, and JSTL) web app whose main functionality is displaying images retrieved from a back-end server. The controller servlet forwards the user to a JSP that in turn uses another Servlet to display the resulting image on that same JSP. Further down, the JSP has a line similar to:

<a href="<c:out value='${imageURL}'/>"><img src="<c:out value='${imageURL}'/>" alt="image view" border="1"></a>

which invokes a GET request on the image-generating servlet causing it to generate the image.

My question is: how do I handle Exceptions thrown by this image-generating servlet?

I already have an error page defined (in web.xml) to handle ServletException within my web app but this doesn't work for this image-generating Servlet, and results in the following errors showing up in my Tomcat server logs:

SEVERE: Exception Processing ErrorPage[exceptionType=javax.servlet.ServletException, location=/WEB-INF/ExceptionPage.jsp]
java.lang.IllegalStateException: Cannot reset buffer after response has been committed

What's my recourse in this situation?

I'd like to be able to handle Exceptions thrown from this image-generating Servlet, and display some error on the main UI or forward the user to another error page.

© Stack Overflow or respective owner

Related posts about java

Related posts about servlets