The moose likes Servlets and the fly likes servlet/jsp exception handling question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet/jsp exception handling question" Watch "servlet/jsp exception handling question" New topic

servlet/jsp exception handling question

Ian Yang
Ranch Hand

Joined: Nov 27, 2001
Posts: 44
In "" it invokes some classes which throws out some special exceptions that can be caught in "". Then some customized exception (subclass of ServletException) is thrown from ""'s doGet() and doPost() method. Eventually "" does "forward(req, res)" to send results to "My.jsp" page, I try to catch ALL the exception in "My.jsp" using "errorpage = ..".
But, it seems once the "" finds any error it goes to a server 500 default page without goes to my special jsp error page. Is it because the exception happened BEFORE the "forward()" ? If so, then how could I make it go to the jsp's special error page ?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17423

Yes it is. The error page is specified in the JSP and if you haven't yet gone to the JSP, there's simply no way to know what the error page even was.
I don't know if explicitly forwarding to an error page is supported. There's some additional context that has to be provided that ordinary JSP's don't have. However you could provide an ordinary JSP, wrap the doGet/doPost code in a try-catch block and have the catch code forward to that page.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: servlet/jsp exception handling question
It's not a secret anymore!