File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP 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
JavaRanch » Java Forums » Java » JSP
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 ?
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
I believe that exceptions descending from ServletException are treated specially by the servlet container. Try changing the parent of your custom exceptions.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
or may be you can try using web.xml file to mentiond "error-page" element of the DTD and do the stuff ....
i've not done it but i guess it should work. because if we set error-page element to be of exception-type and we have appropriate exception defined by you be there in the tag description then when ServletException is thrown, it will first iterate thru error-page directive trying to match the exception and if it can't find a match then it makes a second round to find a match but using getRootCause() method of the ServletException class and hence it should find your custom excepiton which is a subclass of ServletException...
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

He CROSS-POSTED this question. I gave my answer in the servlets forum.

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!