A context may be configured with a custom error handler class that extends either [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java?root=RT_Jetty&view=markup ErrorHandler] for contexts, or [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ErrorPageErrorHandler.java?root=RT_Jetty&view=markup ErrorPageErrorHandler] for webapp contexts.

+

A context may be configured with a custom error handler class that extends either [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java?root=RT_Jetty&view=markup ErrorHandler] for generic contexts, or [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ErrorPageErrorHandler.java?root=RT_Jetty&view=markup ErrorPageErrorHandler] for webapp contexts.

The following methods may be implemented to control the appearance of the error pages:

The following methods may be implemented to control the appearance of the error pages:

Revision as of 09:30, 10 February 2010

Contents

Introduction

There are several ways to create custom error pages in Jetty that are described below.

Define error pages in web.xml

The standard webapp configuration file located in <webapp>/WEB-INF/web.xml can be used to map errors to specific URLs with the <error-page> element. This element creates a mapping between the error-code or exception-type to the location of a resource in the web application.

error-code - integer value

exception-type - fully qualified class name of a Java Exception type

location - location of the resource in webapp relative to the root of the web application. Value should start with "/".

Context file configuration

Context files are normally located in <jetty.home>/contexts/ (see Jetty/Feature/ContextDeployer for more details). Context files can be used to configure the default error handler provided for a context with more flexibility than is available with web.xml, specifically with the support of error code ranges:

Server level 404 error

One may get a 'page not found' when a request is made to the server for a resource that is outside of any registered contexts. As an example, you have a domain name pointing to your public server IP yet no context is registered with jetty to serve pages for that domain. As a consequence, the server, by default, will give a listing of all contexts running on the server.

One of the quickest ways to avoid this behavior is to create a catch all context. Create a "root" web app mapped to the "/" URI. Have the index.html redirect to whatever place with a header directive.