| [ directory ] |
|
2.5 Creating Custom Error PagesMany other directives are available for issuing instructions to the page translator. One of the most useful is called, not surprisingly, page. This directive takes a number of forms, many of which will be encountered throughout this book as needed. One immediately useful option allows a JSP to specify where the user should be directed in the event of an error. Tomcat's default error page, as already shown in Figure 2.1, can be useful to developers but more than a little scary to end users. Ideally, users will never see an error page, but a good site plans for all contingencies and so should include an error page that fits visually with the rest of the site and that allows the user to continue what he or she was doing, to whatever extent possible. Using a custom error page involves two steps. The first is to create the page, which can be another JSP. However, error pages need to be treated differently from regular pages, and so the page translator must be notified that a JSP will be used as an error page by use of the following page directive at the very top of the file: <%@ page isErrorPage="true" %> Once such an error page has been created and properly identified, it can be used in one of two ways. The first is globally, by telling Tomcat which error page to use for each type of error. This is done through a configuration file and is shown in Appendix B. In addition to the global approach, each JSP can specify its own error page through another variation of the page directive, as in
<%@ page errorPage="error_page_url" %>
Here, error_page_url is the URL of the error page, relative to the current page. Both of these versions of the page directive will be demonstrated in the next section. |
| [ directory ] |
|