Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetty custom error pages when running as embedded server

How do you override the default error pages (suffixed with "Powered by Jetty") when running Jetty as an embedded server?

i.e.

Server server = new Server(8080);
server.setHandler(new Handler());

/* configure custom error pages? */

server.start();
server.join();
like image 898
Jonny Rylands Avatar asked Dec 12 '15 22:12

Jonny Rylands


1 Answers

This should solve your problem.

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/*");

    Server jettyServer = new Server(8080);
    jettyServer.setHandler(context);

    ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
    errorHandler.addErrorPage(404, "/missing.html");
    context.setErrorHandler(errorHandler);
like image 87
Ben Avatar answered Nov 06 '22 18:11

Ben