• 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

how to properly catch/display exception in jsp ?

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a scenario that "MyServlet.java" do a "forward(req, res)" to "My.jsp". "MyServlet.java" code throws ServletException, IOExcpetion, plus since "MyServlet.java" calls other database codes which throws SQLException, so I let "MyServlet.java" also throws SQLException.
I want to catch ALL of the above exceptions in "My.jsp" page by using
<%@ page errorPage="error.jsp" %>
The in "error.jsp" page, I use
<%= exception.getMessage() %>
to display the exception.

Now the question is:
1. Does this work ?
2. Does the <%=exception.getMessage() %> show what type of error it is ? i.e. if it is a SQLException, does it show it is SQL exception in the message content ?
Thanks,
Ian
 
Ian Yang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry one correction for my own post, what my "doGet(req, res)" method throws is ServletException, IOException, and my own customized exception (instead of SQLException which is not allowed to be put here).
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
about the second question i'm sure it will determine run time type of the exception and print appropriate type. this is SCJP question.
about the first question, i didn get u. y it will not work? it will thats why u 've errorPage mechanism in the JSP..
regards
maulin
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic