2016-09-06 63 views
0
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://java.sun.com/xml/ns/javaee" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
     version="2.5"> 
    <display-name>Archetype Created Web Application</display-name> 
    <welcome-file-list> 
    <welcome-file>/index.html</welcome-file> 
    </welcome-file-list> 
</web-app> 
Server server = new Server(port); 
WebAppContext webApp = new WebAppContext(); 

webApp.setParentLoaderPriority(true); 
webApp.setThrowUnavailableOnStartupException(true); 
String webapp = classLoader.getResource(".") + "../../" + resourceBase; 
webApp.setDescriptor(webapp + "WEB-INF/web.xml"); 
webApp.setContextPath(contextPath); 
webApp.setResourceBase(webapp); 
webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); 
webApp.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false"); 

server.setHandler(webApp); 
try { 
    server.start(); 
    server.join(); 
} catch (Exception e) { 
    logger.error(e.getMessage(), e); 
} 
16-09-06 18:04:56.116 [qtp973576304-16] DEBUG org.eclipse.jetty.server.Server - RESPONSE for/h=true 
404 null 
Date: Tue, 06 Sep 2016 10:04:56 GMT 
Cache-Control: must-revalidate,no-cache,no-store 
Content-Type: text/html;charset=iso-8859-1 

回答

0

刪除../../

File webappDir = new File(new File(classLoader.getResource(".").toURI()).getParentFile().getParentFile().getCanonicalFile().getAbsolutePath() + "/" + resourceBase);