Skip to content

Instantly share code, notes, and snippets.

@gregw
Created March 5, 2015 06:40
Show Gist options
  • Save gregw/423e6c26d19b42f62ea0 to your computer and use it in GitHub Desktop.
Save gregw/423e6c26d19b42f62ea0 to your computer and use it in GitHub Desktop.
public class OneServletContext
{
public static void main( String[] args ) throws Exception
{
Server server = new Server(8080);
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
((ErrorPageErrorHandler)context.getErrorHandler()).addErrorPage(404,"/some/uri/for/404");
((ErrorPageErrorHandler)context.getErrorHandler()).addErrorPage(500,"/some/uri/for/500");
((ErrorPageErrorHandler)context.getErrorHandler()).addErrorPage(NullPointerException.class,"/null/pointer/uri");
context.setContextPath("/");
context.setResourceBase(System.getProperty("java.io.tmpdir"));
server.setHandler(context);
// Add dump servlet
context.addServlet(DumpServlet.class, "/dump/*");
// Add default servlet
context.addServlet(DefaultServlet.class, "/");
server.start();
server.join();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment