Jetty 9.4进行了不必要的重定向

时间:2017-03-06 08:47:38

标签: java jetty-9

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

1 个答案:

答案 0 :(得分:0)

同事found the solution

resHandler.setRedirectWelcome(false);