Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...