从jetty 9.3升级到9.4后,我发现jetty从http://localhost:port/重定向到http://localhost:port/index.html
在./src/main/webapp
下有index.html,所以本地它工作正常,但重定向本身是一个问题,因为我使用nginx作为代理,重定向的localhost导致问题。我也不需要重定向。
这是我用来启动jetty的代码:
int httpPort = 9000;
ResourceHandler resHandler = new ResourceHandler();
resHandler.setDirectoriesListed(false);
resHandler.setResourceBase("./src/main/webapp");
Server server = new Server();
ServletContextHandler servHandler = new ServletContextHandler();
servHandler.setContextPath("/");
servHandler.addServlet(new ServletHolder(new InvalidRequestServlet()), "/*");
FilterHolder guiceFilter = new FilterHolder(injector.getInstance(GuiceFilter.class));
servHandler.addFilter(guiceFilter, "/*", EnumSet.allOf(DispatcherType.class));
ServerConnector http = new ServerConnector(server, new HttpConnectionFactory());
http.setPort(httpPort);
server.setConnectors(new Connector[]{http});
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]{resHandler,servHandler});
server.setHandler(handlers);
server.start();