问题
Apparently, ResourceHandler stop hosting files with jetty 9 - 404 not found error (works fine with jetty 8). Here is the code:
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(true);
resourceHandler.setResourceBase("some_resource_base");
HandlerList handlerList = new HandlerList();
handlerList.setHandlers(new Handler[]{servletHandler, resourceHandler});
server.setHandler(handlerList);
server.start();
This quistion with the accepted answer does not seem to work against jetty 9 - Serving static files w/ embedded Jetty
回答1:
Assuming that servletHandler is a ServletContextHandler
(Note: it best not be an actual ServletHandler, as that's an internal class, not meant to be instantiated directly)
Then the resourceHandler will never be called, as the DefaultServlet processing (or Default404Servlet) at the end of the ServletContextHandler chain will always respond, not allowing resourceHandler to even execute.
If you have a ServletContextHandler, do not use ResourceHandler use the DefaultServlet in that ServletContextHandler to setup and serve your static files.
来源:https://stackoverflow.com/questions/28346438/resourcehandler-stop-hosting-files-with-jetty-9-404-not-found-error-works-fin