Forums Register Login
JSP exception implicit object
I have a little Java web application. It uses MVC, with a HttpServlet as controller and several JSPs for view.

The Servlet captures several exceptions like SQLExceptions, and I need process these exceptions in an "ErrorPage" JSP. (JSP with directive <%@page isErrorPage="true" %>.) The problem is, How can I set "exception" JSP implicit object from the Servlet?

(I'm using a RequestDispatcher object to pass control to error page.)

Why are you bothering to catch the exception? Simply declare the error handling in the deployment descriptor, and let the exception propagate out to it. You are making it much more complicated than it needs to be.
Thank you, Bear Bibeault!
My Servlet (HttpServlet) analyzes request parameters in order to query a database, and then passes control to a JSP page, according to that analysis.
If this Servlet catches a SQLException, I need to set "exception" JSP implicit object with SQLException to pass it to a JSP ErrorPage.
I can't let this SQLException propagate, because HttpServlet's methods throws only IOException and ServletException.
The Servlet (controller) can catch SQLException, but I can not throw this Exception from doPost() method.
(I need this behavior for a class demostration.)
Thank you, again.
Well, first of all I question the design that lets a SQLException propagate to the presentation layer -- but without getting into that, you can wrap the SQLException as the root cause of a ServletException and let that propagate.
OK, I'll try it.
Thank you very much!
Thank you, Bear Bibeault!
It works throwing ServletException and then the container catched it by mean deployment descriptor with <exception-type> tag to pass control to JSP error page.

This thread has been viewed 531 times.

All times above are in ranch (not your local) time.
The current ranch time is
Oct 17, 2018 18:28:43.