I have a Spring MVC project where I use controller advice to handle errors that occur in controllers. However, I also want to display a good error page if the error occurs in JSP files (although this should not happen!). Therefore, I added the following file to my web.xml project:
<error-page> <error-code>500</error-code> <location>/WEB-INF/views/application/error/view-error.jsp</location> </error-page> <error-page> <exception-type>java.lang.Exception</exception-type> <location>/WEB-INF/views/application/error/view-error.jsp</location> </error-page>
If I specifically cause an error in JSTL, the content of view-error.jsp displayed fine. However, the content is added to the output of the JSP file in which the error occurred. For example, if an error occurs in display-users.jsp on line 50, the result is that the result that was generated before the error occurred (line 1-50) adds content to view-error.jsp .
This is very undesirable as it creates a funky error page. And since I canโt say where the exception will be thrown (if I could, I would fix the error), then what the user sees will most likely look bad.
I suppose, because the output is already in the buffer and may already be sent to the client? Is there a way to fix this, or perhaps an alternative approach? Thanks!
java jsp
Andy0708
source share