Jetty 9.4 做了不必要的重定向
Jetty 9.4 does unnecessary redirection
在我从 jetty 9.3 升级到 9.4 后,我注意到 jetty 从 http://localhost:port/ to http://localhost:port/index.html
进行了重定向
./src/main/webapp
下有 index.html,因此在本地它工作正常,但重定向本身是一个问题,因为我使用 nginx 作为代理,重定向的 localhost 导致问题。另外,重定向对我来说似乎是不必要的。
这是我用来启动码头的代码:
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();
一位同事found the solution:
resHandler.setRedirectWelcome(false);
在我从 jetty 9.3 升级到 9.4 后,我注意到 jetty 从 http://localhost:port/ to http://localhost:port/index.html
进行了重定向./src/main/webapp
下有 index.html,因此在本地它工作正常,但重定向本身是一个问题,因为我使用 nginx 作为代理,重定向的 localhost 导致问题。另外,重定向对我来说似乎是不必要的。
这是我用来启动码头的代码:
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();
一位同事found the solution:
resHandler.setRedirectWelcome(false);