Essential ATG Dynamo Training - Got atg Certified Relationship Management Developer?
This is not an official ATG site: ATG, Dynamo, Scenario Server and Personalization Server are trademarks or registered trademarks of Art Technology Group
Articles Exercises Resources Links Search

JSP Error Page Basics

This is easy when you see it, so here it is!

TestErrorPage.jsp

Here's the page that may throw an error:

<%@ page errorPage="MyErrorPage.jsp" %>
<HTML>
<HEAD><TITLE>Test Error Page</TITLE></HEAD>
<BODY>
<H2>Throw Exception!</H2>
<% String nullString = null; %>
<!-- Ooops -->
<% nullString.length(); %>

</BODY>
</HTML>

Notice the page directive at the top specifying a custom error page

MyErrorPage.jsp

<%@ page isErrorPage="true" %>
<HTML>
<HEAD><TITLE>My Error Page</TITLE></HEAD>
<BODY>
<H2>Exception Information</H2>
<TABLE>

<tr>
<td>Exception Class:</td>
<td><%= exception.getClass() %></td>
</tr>

<tr>
<td>Message:</td>
<td><%= exception.getMessage() %></td>
</tr>

</TABLE>
</BODY>
</HTML>

Notice here the page directive isErrorPage, this gives us access to the implicit object 'exception' from where we can display (or act upon) the actual exception.

The Result

When we browse to TestErrorPage.jsp, an exception is thrown. It's caught by the container and passed on to our error page, which is then called to display a response to the client. The user's browser still shows the original request URL.



Advertise your Training Programs for Free!