Oracle JavaServer Pages Developer's Guide and Reference Release 8.1.7 Part Number A83726-01 |
|
While a JSP page is executing and processing client requests, runtime errors can occur either inside the page or outside the page (such as in a called JavaBean). This section describes the JSP error processing mechanism and provides a simple example.
Any runtime error encountered during execution of a JSP page is handled using the standard Java exception mechanism in one of two ways:
You can specify the URL of an error page by setting the errorPage
parameter in a page
directive in the originating JSP page. (For an overview of JSP directives, including the page
directive, see "Directives". )
In a servlet 2.2 environment, you can also specify a default error page in the web.xml
deployment descriptor with instructions such as the following:
<error-page> <error-code>404</error-code> <location>/error404.html</location> </error-page>
(See the Sun Microsystems Java Servlet Specification, Version 2.2 for more information about default error pages.)
An error page must have a page
directive setting the isErrorPage
parameter to true
.
The exception object describing the error is a java.lang.Exception
instance that is accessible in the error page through the implicit exception
object.
Only an error page can access the implicit exception
object. (For information about JSP implicit objects, including the exception
object, see "Implicit Objects".)
See the next section, "JSP Error Page Example", for an example of error page usage.
The following example, nullpointer.jsp
, generates an error and uses an error page, myerror.jsp
, to output contents of the implicit exception
object.
<HTML> <BODY> <%@ page errorPage="myerror.jsp" %> Null pointer is generated below: <% String s=null; s.length(); %> </BODY> </HTML>
<HTML> <BODY> <%@ page isErrorPage="true" %> Here is your error: <%= exception %> </BODY> </HTML>
This example results in the following output:
|
Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|