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.