Skip to content

Latest commit

 

History

History
52 lines (45 loc) · 2.14 KB

File metadata and controls

52 lines (45 loc) · 2.14 KB

Default Handler

Info

  • Classname: org.eclipse.jetty.server.handler.DefaultHandler

  • Maven Artifact: org.eclipse.jetty:jetty-server

  • Javadoc: {JDURL}/org/eclipse/jetty/server/handler/DefaultHandler.html

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 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.
    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();