ResourceHandler stop hosting files with jetty 9 - 404 not found error (works fine with jetty 8)

戏子无情 提交于 2019-12-18 07:11:32

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!