Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unable to throw exceptions in servlet, please help!!

807591Apr 3 2008 — edited Apr 4 2008
Hi, I am trying to create a simple servlet app for a uni assignment, but im having trouble.

Some of the code im using in the servlet is:
        int fail = 1/0;
        
        } catch (Exception e) {
            throw new ServletException("Servlet caught a ServletException: " + e.getMessage());
        }
The reason for this is that im trying to se if I can get any exceptions to be handle, as I currently have around 5 in my project and none of them get re-directed! As well as this piece of code I have two jsp, one for error code 500 and one for ServletException errors, both referenced in the xml file. The code for the jsps looks like this:
<%@ page contentType="text/html"%><%@ page language="java"%><%@ page isErrorPage="true" %>
<html>
    <head>
        <title>Custom Error Page for CreateExceptionServlet</title>
    </head>
    <body>
        <b>
            <font face="Arial" size="2" color="#009999" align="left">This is an error JSP!! Look at the error message below: 
            <%=exception.getMessage() %>
            </font>
        </b>
    </body>
</html>
When I run the app, everything runs fine if I dont put in the purposeful mistaken (the app is quite extensive and everything works how I want it to), but when I put the mistake in, all I ever get is the IE explorer "cannot display page" page. If I take out the jsps and the error handling page info from the xml page, I get the standard java exception handling page which is not very nice to look at and has too much detail. So it would seem that my jsps are incorrectly written or I have linked thm wrong somehow, is there a piece of code im missing?? Any help is much appreciated, Charlie.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 2 2008
Added on Apr 3 2008
70 comments
1,067 views