6

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();
Jonny Rylands
  • 193
  • 4
  • 12
  • 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 Dec 14 '15 at 14:18
  • @JoakimErdfelt Jetty is coming along with Jenkins. Yes, i am happy by just hiding the version details from the page. – i_am_beginner Jan 10 '20 at 05:35

1 Answers1

11

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);
Ben
  • 696
  • 9
  • 19
  • 1
    Here is the documentation for 9.4.v20161208 which is quite recent one: http://download.eclipse.org/jetty/9.4.0.v20161208/apidocs/org/eclipse/jetty/servlet/ErrorPageErrorHandler.html – zloster Apr 06 '17 at 16:57