I have a simple (servlet, JSP, and JSTL) web app whose main functionality is Back-End Server. The controller servlet takes the user forward for a JSP, in return for which another service is used to display the resulting image on that same JSP. Next down, JSP has the same line:
& lt; A href = "& lt; c: out value = '$ {imageURL}' / & gt; & Gt; & Lt; Img src = "& lt; c: out value = '$ {imageURL}' / & gt; alt =" image view "range =" 1 ">
which allows a GET request on the image-generating servlet, so that the image is generated.
My question is: to handle ServletException in my web app already The error page is defined (in web.xml) but it does not work for this image-generating circlet, and the result is showing the following error. In my Tomcat server log:
SEVERE: Exception processing error [exception type = javax.servlet.ServletException, location = / WEB-INF / ExceptionPage.jsp] java.lang.IllegalStateException: Can not reset, buffer after response
What is my support in this situation?
I want to be able to handle the exceptions thrown by this image-generating circlet, and display some error on the main UI or user Please send it to another error page.
You can not change but the response to redirect is sending an error page while is the response to change the whole response is already too late. You can not ask back clients from the already sent bytes. This is the same as InvalidState Exception
Here is no return.
Best of what you can do is simply log the exception or rewrite the code so that it does not write any for the response (do not set the response header) while the business logic has yet to do its work Not completed. Once you determine that business logic has not thrown any exception, start the reaction (and even indirectly) if business logic has put an exception, but the response still does not touch , You can throw it safely so that it ends in an error page. However, in the case of an image servlet, you can stream some of the standard 404.gif
instead. This is because you & lt; Img & gt; Can not display another HTML (error) page in the element
and you can not change the URL of the parent JSP / HTML page as it differs from request.
Comments
Post a Comment