//  ========================================================================
//  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
//  ========================================================================
//  All rights reserved. This program and the accompanying materials
//  are made available under the terms of the Eclipse Public License v1.0
//  and Apache License v2.0 which accompanies this distribution.
//
//      The Eclipse Public License is available at
//      http://www.eclipse.org/legal/epl-v10.html
//
//      The Apache License v2.0 is available at
//      http://www.opensource.org/licenses/apache2.0.php
//
//  You may elect to redistribute this code under either of these licenses.
//  ========================================================================

[[default-handler]]
=== Default Handler

[[default-handler-metadata]]
==== Info

* Classname: `org.eclipse.jetty.server.handler.DefaultHandler`
* Maven Artifact: org.eclipse.jetty:jetty-server
* Javadoc: {JDURL}/org/eclipse/jetty/server/handler/DefaultHandler.html
* Xref: {JXURL}/org/eclipse/jetty/server/handler/DefaultHandler.html

[[default-handler-usage]]
==== Usage

A simple handler that is useful to terminate handler chains with a clean fashion. 
As in the example below, if a resource to be served is not matched within the resource handler, the DefaultHandler will take care of producing a 404 page. 
This class is a useful template to either extend and embrace or simply provide a similar implementation for customizing to your needs. 
There is also an link:#error-handler[Error Handler] that services errors related to the servlet api specification so it is best to not get the two confused.

_____
[NOTE]
The DefaultHandler will also handle serving out the flav.ico file should a request make it through all of the other handlers without being resolved.
_____

[source, java, subs="{sub-order}"]
----

    Server server = new Server(8080);
    HandlerList handlers = new HandlerList();
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setBaseResource(Resource.newResource("."));
    handlers.setHandlers(new Handler[]
    { resourceHandler, new DefaultHandler() });
    server.setHandler(handlers);
    server.start();

      
----
