background image

Mapping Errors to Error Screens

<< Setting Initialization Parameters | Declaring Resource References >>
<< Setting Initialization Parameters | Declaring Resource References >>

Mapping Errors to Error Screens

3. Expand the Web Pages node and then the WEB-INF node.
4. Double-click web.xml.
5. Click Servlets at the top of the editor pane.
6. After entering the servlet's name, class, and URL pattern, click the Add button under the
Initialization Parameters table.
7. In the Add Initialization Parameter dialog:
a. Enter the name of the parameter in the Param Name field.
b. Enter the parameter's value in the Param Value Field.
c. Click OK.
Alternatively, you can edit the XML of the web.xml file directly by clicking XML at the top of the
editor pane and using the following elements to add a context parameter:
A param-name element that specifies the name of the initialization parameter
A param-value element that specifies the value of the initialization parameter
An init-param element that encloses the previous two elements
Mapping Errors to Error Screens
When an error occurs during execution of a web application, you can have the application
display a specific error screen according to the type of error. In particular, you can specify a
mapping between the status code returned in an HTTP response or a Java programming
language exception returned by any web component (see
"Handling Servlet Errors" on
page 105
) and any type of error screen.
To set up error mappings using NetBeans IDE, do the following:
1. Open the project if you haven't already.
2. Expand the project's node in the Projects pane.
3. Expand the Web Pages node and then the WEB-INF node.
4. Double-click web.xml.
5. Click Pages at the top of the editor pane.
6. Expand the Error Pages node.
7. Click Add.
8. In the Add Error Page dialog:
a. Click Browse to locate the page that you want to act as the error page.
b. Enter the HTTP status code that will cause the error page to be opened in the Error Code
field.
c. Enter the exception that will cause the error page to load in the Exception Type field.
d. Click OK.
Configuring Web Applications
Chapter 3 · Getting Started with Web Applications
93