background image

Creating Static Content

<< Handling JSP Page Errors | Creating Dynamic Content >>
<< Handling JSP Page Errors | Creating Dynamic Content >>

Creating Static Content

<%@ page isErrorPage=
"true" %>
This directive makes an object of type
javax.servlet.jsp.ErrorData
available to the error page so
that you can retrieve, interpret, and possibly display information about the cause of the
exception in the error page. You access the error data object in an EL (see
"Unified Expression
Language" on page 146
) expression by way of the page context. Thus,
${pageContext.errorData.statusCode}
retrieves the status code, and
${pageContext.errorData.throwable}
retrieves the exception. You can retrieve the cause of
the exception using this expression:
${pageContext.errorData.throwable.cause}
For example, the error page for Duke's Bookstore is as follows:
<%@ page isErrorPage=
"true" %>
<%@ taglib uri=
"http://java.sun.com/jsp/jstl/core"
prefix=
"c" %>
<%@ taglib uri=
"http://java.sun.com/jsp/jstl/fmt"
prefix=
"fmt" %>
<html>
<head>
<title><fmt:message key=
"ServerError"/></title>
</head>
<body bgcolor=
"white">
<h3>
<fmt:message key=
"ServerError"/>
</h3>
<p>
: ${pageContext.errorData.throwable.cause}
</body>
</html>
Note ­
You can also define error pages for the WAR that contains a JSP page. If error pages are
defined for both the WAR and a JSP page, the JSP page's error page takes precedence.
Creating Static Content
You create static content in a JSP page simply by writing it as if you were creating a page that
consisted only of that content. Static content can be expressed in any text-based format, such as
HTML, Wireless Markup Language (WML), and XML. The default format is HTML. If you
want to use a format other than HTML, at the beginning of your JSP page you include a page
directive with the contentType attribute set to the content type. The purpose of the
contentType
directive is to allow the browser to correctly interpret the resulting content. So if
you wanted a page to contain data expressed in WML, you would include the following
directive:
Creating Static Content
The Java EE 5 Tutorial · September 2007
144