Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
11.9 The errorPage Attribute
261
11.9 The errorPage Attribute
The
errorPage
attribute specifies a JSP page that should process any excep
tions (i.e., something of type
Throwable
) thrown but not caught in the cur
rent page. It is used as follows:
<%@ page errorPage="Relative URL" %>
The exception thrown will be automatically available to the designated
error page by means of the
exception
variable. See Listings 11.5 and 11.6
for examples.
11.10 The isErrorPage Attribute
The
isErrorPage
attribute indicates whether or not the current page can act
as the error page for another JSP page. Use of
isErrorPage
takes one of the
following two forms:
<%@ page isErrorPage="true" %>
<%@ page isErrorPage="false" %> <%! Default %>
For example, Listing 11.5 shows a JSP page to compute speed based upon
distance and time parameters. The page neglects to check if the input param
eters are missing or malformed, so an error could easily occur at run time.
However, the page designated
SpeedErrors.jsp
(Listing 11.6) as the page
to handle errors that occur in
ComputeSpeed.jsp
, so the user does not
receive the typical terse JSP error messages. Figures 11 9 and 11 10 show
results when good and bad input parameters are received, respectively.
Listing 11.5 ComputeSpeed.jsp
Computing Speed
HREF="JSP Styles.css"
TYPE="text/css">
<%@ page errorPage="SpeedErrors.jsp" %>
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved