Java Reference
In-Depth Information
Errors can occur in a JSP in two different phases of its life. The first type of error, which
occurs during the initial request, is known as a translation-time error . The second type of JSP
error occurs during subsequent requests and is know as a request-time error . These errors are
discussed in the following sections.
JSP Translation-Time Errors
The first type of JSP error occurs when a JavaServer Page is first requested and goes through
the initial translation from a JSP source file into a corresponding servlet class file. These
translation-time errors are usually the result of compilation failures. They are reported to the
requesting client with an error status code 500 or Server Error and usually contain the
reported compilation error. The JSP engine handles translation-time errors.
JSP Request-Time Errors
The second type of JSP error occurs during request time. These errors are runtime errors that
can occur either in the body of the JSP page or in some other object that is called from the
body of the JSP page.
Request-time errors result in an exception being thrown. These exceptions can be caught and
appropriately handled in the body of the calling JSP, which would be the end of the error.
Those exceptions that are not caught result in the forwarding of the client request, including
the uncaught exception, to the error page specified by the offending JSP. The following sec-
tions describe, in detail, how to define and implement JSP error pages.
Creating a JSP Error Page
To create a JSP error page, you need to create a basic JavaServer Page and then tell the JSP
engine that the page is an error page. You do this by setting its page attribute isErrorPage to
true . Listing 18.1 contains a sample error page.
<body text=”red”>
<%@ page isErrorPage=”true” %>
<!-- Use the implicit exception object, which holds a reference -->
<!-- to the thrown exception. -->
Search WWH ::

Custom Search