本文介绍了ResourceHandler停止托管文件与码头9 - 404未找到错误(适用于码头8)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,$ code> ResourceHandler 停止托管文件与码头9 - 404未找到错误(适用于码头8)。以下是代码:

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

已接受的答案的这个问题似乎不适用于 jetty 9 -

解决方案

假设 servletHandler 是一个 ServletContextHandler / p>

(注意:最好不要是一个实际的 ServletHandler ,因为这是一个内部类,不是被直接实例化)



然后,$ code> resourceHandler 永远不会被调用,因为 DefaultServlet ServletContextHandler 链末尾处理(或 Default404Servlet )回复,不允许 resourceHandler 甚至执行。



如果你有一个 ServletContextHandler ,不要使用 ResourceHandler 使用 DefaultServlet ServletContextHandler 中设置和提供静态文件。


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

解决方案

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.

这篇关于ResourceHandler停止托管文件与码头9 - 404未找到错误(适用于码头8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 16:43