我很难弄清楚目录路径如何为这个jetty HTTP服务器工作。我在浏览器中尝试了http://localhost:8080/test,它没有按预期列出目录文件(存在C:\ test目录)。我至少使用正在尝试使用的目录的正确路径?浏览器网址是否正在尝试更正?
Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(8080);
server.addConnector(connector);
ResourceHandler resourceHandle = new ResourceHandler();
resourceHandle.setDirectoriesListed(true);
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setWelcomeFiles(new String[] { "index.html" });
resource_handler.setResourceBase("/test");
System.out.println("resourcebase: " + resource_handler.getResourceBase()); //not working
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
server.setHandler(handlers);
server.start();
server.join();
编辑:打印甚至无法正常工作且没有捕获异常
try {
startFileHTTP();
} catch (Exception e) {
System.out.println("HTTP error");
e.printStackTrace();
}
答案 0 :(得分:0)
我认为您的问题出在
resource_handler.setResourceBase("/test");
您确定基本路径是C:\
吗?