我必须使用我的 html 文件中的自定义页面更改 404 错误页面。我写了这段代码,但它不起作用,和/或我不知道如何使用它。
public static void main(String[] args) throws Exception {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/rac");
Server jettyServer = new Server(8080);
context.setWelcomeFiles(new String[] { "./src/main/resources/index.html" });
ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
errorHandler.addErrorPage(HttpStatus.NOT_FOUND_404, "./src/main/resources/error.html");
context.setErrorHandler(errorHandler);
// HTML
DefaultServlet defaultServlet = new DefaultServlet();
ServletHolder holderPwd = new ServletHolder("default", defaultServlet);
holderPwd.setInitParameter("resourceBase", "./src/main/resources/index.html");
context.addServlet(holderPwd, "/*");
// SERVICES
ServletHolder jerseyServlet = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,
"/ajax/*");
jerseyServlet.setInitOrder(0);
jerseyServlet.setInitParameter("jersey.config.server.provider.classnames",
DiskServiceWS.class.getCanonicalName() + "," + RamServiceWS.class.getCanonicalName() + ","
+ CpuServiceWS.class.getCanonicalName());
jettyServer.setHandler(context);
try {
jettyServer.start();
jettyServer.join();
} finally {
jettyServer.destroy();
}
}
largeQ
相关分类