Configure Error Pages
An error-page element defines a resource to handle errors of a specific type. Each error-page element contains an error-code element and a location element. The error-code defines the HTTP error code the element handles. The location element defines the path for forwarding the request. Note that the location can be any resource reachable by the servlet container, including a file within the context, another servlet, or even a remote HTTP resource. For example, the web.xml fragment below configures the container to return the contents of the file 404.html when a servlet returns HTTP error code 404.
<error-page>
<error-code>404</error-code>
<location>/404.html</location>
</error-page>
In a location element, the path to a file is relative to the root directory of the context. In the example above, the file 404.html must be located in the root directory of the context. The directory tree for the example above should look similar to:
apps\
servlets\
examples\
404.html
WEB-INF\
web.xml
As shown above, the 404.html file is in the context root directory, examples, not in the WEB‑INF directory.