6
votes

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();
1
What version of Jetty (be specific, as the answer is jetty version specific)? Are you just wanting to turn off the "Powered by Jetty?" or something entirely new? - Joakim Erdfelt
@JoakimErdfelt Jetty is coming along with Jenkins. Yes, i am happy by just hiding the version details from the page. - i_am_beginner

1 Answers

11
votes

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