Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to properly catch/display exception in jsp ?

 
Ian Yang
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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).
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic