With this setting, resourceHandler will never be called, since the processing of the DefaultServlet (or Default404Servlet ) at the end of the ServletContextHandler chain will always respond, preventing the resourceHandler even executing.
If you have a ServletContextHandler , do not use resourceHandler use the DefaultServlet in this ServletContextHandler to configure and maintain your static files.
resourceHandler very simplified if you want more controls, use the DefaultServlet configured instead of ServletContextHandler .
Okay, with that out of the way ...
ServletContextHandler.setBaseResource(Resource) is the place for ServletContext itself to configure its contextual resourceBase .
(Note: the setResourceBase () parameter is a URL string that can point to the file:// directory or even to jar:file:// . Almost everything that is supported by Resource.newResource(String) )
${resourceBase}/ is the search point for various methods in javax.servlet.ServletContext , for example:String getRealPath(String path)URL getResource(String path)InputStream getResourceAsStream(String path)Set<String> getResources(String path)
- Requested resources that do not match any of your servlets or filters will be processed using
DefaultServlet , which can serve static resources (such as *.html , *.css , *.js ) from the specified ${resourceBase}/${request.pathInfo}
resourceHandler not involved in ServletContextHandler , not suitable for mixing with ServletContextHandler .
Also, be sure to set ServletContextHandler.setContextPath(String) to your desired context path (usually "/" )
And yes, you can even have multiple DefaultServlet configurations in one ServletContextHandler .
Joakim Erdfelt Feb 09 '15 at 20:51 2015-02-09 20:51
source share