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!

JSP unable to display errors thrown from other pages

807591Apr 4 2008 — edited Apr 4 2008
Ok, so I have a web application built for a uni project in netbeans which accesses and modifies an SQL database. One of the requirement is to display useful error messages to the user of something goes wrong, so in for all the major tasks in the main servlet, I have wrapped the exceptions as followed:
try {
blah blah
} catch (SQLException e) {
            throw new ServletException(("Error intitialising database"), e);
        }
In my XML page I set up an error page to catch ServletExceptions though the XML page editor (so I know the location if right) and the code looks like this:
 
   <error-page>
        <exception-type>javax.servlet.ServletException</exception-type>
        <location>/error.jsp</location>
    </error-page>
Finally, I have a basic JSP that looks like this:
<%@ page contentType="text/html" isErrorPage="true" %>
<html>
    <head>
        <title>Error Page</title>
    </head>
    <body>
        <b>
                <%=exception.getMessage() %>
        </b>
    </body>
</html>
Everything compiles and runs as expected when there is no mistsake in the servlet. When I make mistake to do with the SQL, I get an internet explorer code 500 page "the website could not display the page", so its not displaying my JSP.
Now, when I change the <exception-type>javax.servlet.ServletException</exception-type> part to:

<exception-type>javax.wrongwrongwrong.ServletException</exception-type>

I get java's exception page with stack trace and all when I load the server, which make sense, the exception does not match the one that my JSP is set to handle, and so it handles it as it would normally.

When I change the <location>/error.jsp</location> part to:

<location>/wrongwrongwrong.jsp</location>

I get a code 404, "the webpage cannot be found", which also makes sense.

So it is only when I do it right that I get a 500, which makes me think its a JSP page error, but I have tried many diffent layout, what could possiibly be going wrong here??
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 2 2008
Added on Apr 4 2008
9 comments
907 views