Can a JSP error page cause problems?

In java applications, it is possible to handle exceptions by defining an error page in web.xml:

<error-page>
<error-code>500</error-code>
<location>/error500.jsp</location>
</error-page>

I am wondering if there might be a problem with the definition of the JSP error page (as opposed to the HTML error page). Because JSPs are server side. Could there be a scenario when the server is "half dead", throws an exception, tries to redirect to the page with an error, but cannot display it because it is "half dead"?

By “half dead,” I mean that the server is in a state where some things are still working, but other things are not working. In particular, I mean that everything that controls redirecting to the error page defined in web.xml still works, but the actual JSP rendering doesn't work for some reason (something throws an exception).

I really have not seen such a problem, but I wonder if this is possible. Because then the potential HTML error page will work (because it has no server-side logic), while the JSP error page will not work.

And if so, how can I “return” to the HTML error page when the JSP error page fails? I still want to use the JSP error page to display information about the errors returned in the response, but if this is not possible, I want to display the HTML page.

Hope this makes sense ...

+5
source share
2 answers

I found a solution:

  • Identify 500 error for redirecting to servlet (instead of page)
  • Define a 404 error page as well - make it a simple HTML page.
  • In the servlet, redirect to the JSP 500 error page.
  • All the logic in the servlet is surrounded by a try-catch block. The catch block executes response.sendError(HttpServletResponse.SC_NOT_FOUND);, which redirects to the 404 error page defined in web.xml.
+1
source

, , , error.jsp , (, db, , error.jsp, - db - , ?).

error.jsp .

0

All Articles