Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
DOCUMENTATION: Jetty 6 - this wiki. Jetty 7 - at Eclipse. Jetty8 - at Eclipse. Jetty 9 - at Eclipse.
Skip to end of metadata
Go to start of metadata
You are viewing an old version of this page. View the current version. Compare with Current ·  View Page History

3 ways in creating custom error pages

1. 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 typ 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 "/".

Error code example:

Exception example:

2. context file configuration.

Context files are nomrall located in <jetty.home>/contexts/?.xml (see ContextDeployer for more detail). 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:

3. Custom error handle class.

A context may be configured with a custom error handler class that extends ErrorHandler (for webapp contexts
it must extend ErrorPageErrorHandler).

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

  • public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException
  • void handleErrorPage(HttpServletRequest request, Writer writer, int code, String message) throws IOException
  • void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException
  • void writeErrorPageHead(HttpServletRequest request, Writer writer, int code, String message) throws IOException
  • void writeErrorPageBody(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException
  • void writeErrorPageMessage(HttpServletRequest request, Writer writer, int code, String message,String uri) throws IOException
  • void writeErrorPageStacks(HttpServletRequest request, Writer writer) throws IOException

The custom error handler may be set on the context via the API or via a context configuration file. For example a custom error handling class can be added to the javadoc context with:

Labels
  • None
Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery