• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP exception implicit object

 
Adrian Cordoba
Greenhorn
Posts: 26
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Adrian Cordoba
Greenhorn
Posts: 26
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Adrian Cordoba
Greenhorn
Posts: 26
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I'll try it.
Thank you very much!
 
Adrian Cordoba
Greenhorn
Posts: 26
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!