Java Reference
In-Depth Information
L ISTING 18.1
Continued
Error: <%= exception.getMessage() %> has been reported.
</body>
</html>
There are two lines of code you need to look at to understand just how easy it is to create a
JSP error page. The first is the page directive line, which indicates that this JSP is an error
page. This code snippet is
<%@ page isErrorPage=”true” %>
The second line of code designates where the thrown exception is being used. This line is
Error: <%= exception.getMessage() %> has been reported.
You will notice that this line uses the implicit exception object that is part of all JSP error
pages. The exception object holds the reference to the unhandled exception that was thrown
in the offending JSP.
18
To gain a complete understanding of how the error page works, take a look at the servlet code
that is generated from the JSP error page. The following code snippet contains the
_jspService() method generated from Listing 18.1:
N OTE
The generated code included in the examples will differ depending on the applica-
tion server used.
public void _jspService(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
Throwable exception =
(Throwable)request.getAttribute(“javax.servlet.jsp.jspException”);
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
 
Search WWH ::




Custom Search