• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP exception implicit object

 
Greenhorn
Posts: 27
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 27
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 27
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I'll try it.
Thank you very much!
 
Adrian Cordoba
Greenhorn
Posts: 27
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
reply
    Bookmark Topic Watch Topic
  • New Topic