Sto incorporando Jetty (versione 7.4.5.v20110725) in un'applicazione java. Sto servendo pagine JSP in ./webapps/jsp/ utilizzando WebAppContext di Jetty, ma se visito localhost: 8080/jsp/Ottengo l'elenco di directory di Jetty per l'intero contenuto di ./webapps/jsp/. Ho provato a impostare il parametro dirAllowed su false su WebAppContext e non modifica il comportamento dell'elenco di directory.Come disabilitare l'elenco di directory per WebAppContext di Jetty?
La disattivazione dell'elenco di directory su ResourceHandler avviene semplicemente passando a false per setDirectoriesListed, funziona come previsto. Qualcuno può dirmi come farlo per WebAppContext?
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.webapp.WebAppContext;
public class Test {
public static void main(String[] args) throws Exception {
Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setHost("127.0.0.1");
connector.setPort(8080);
server.addConnector(connector);
// Create a resource handler for static content.
ResourceHandler staticResourceHandler = new ResourceHandler();
staticResourceHandler.setResourceBase("./webapps/static/");
staticResourceHandler.setDirectoriesListed(false);
// Create context handler for static resource handler.
ContextHandler staticContextHandler = new ContextHandler();
staticContextHandler.setContextPath("/static");
staticContextHandler.setHandler(staticResourceHandler);
// Create WebAppContext for JSP files.
WebAppContext webAppContext = new WebAppContext();
webAppContext.setContextPath("/jsp");
webAppContext.setResourceBase("./webapps/jsp/");
// ??? THIS DOES NOT STOP DIR LISTING OF ./webapps/jsp/ ???
webAppContext.setInitParameter("dirAllowed", "false");
// Create a handler list to store our static and servlet context handlers.
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { staticContextHandler, webAppContext });
// Add the handlers to the server and start jetty.
server.setHandler(handlers);
server.start();
server.join();
}
}
Funziona anche con Jetty 8.1.4.v20120524. Grazie!!! – Tarlog
E con 9.0.2.v20130417 – joscarsson
e anche con 9.2.x! – Nishant