2016-05-13 58 views
0

我使用的是tomcat 8,我有一個函數可以查看和更新​​配置文件圖片。這些文件位於外部文件夾中。在servlet.xml中Tomcat上下文docbase

<Context docBase="C:/assets" path="mywebapp/files"/> 

它的正常工作在我本地的Tomcat使用此代碼檢索但在遠程服務器訪問時,它不被顯示在新創建的文件。我必須在服務器中重新啓動tomcat,以便顯示新圖像。

我也試過這個

<Context docBase="C:/assets" path="mywebapp/files" reloadable="true"/> 

,但仍然沒有奏效

任何想法沒有如何重新啓動Tomcat?

+0

「C:/ assets」是鏈接嗎? –

回答

0

我相信你的docBase行屬於server.xml而不是servlet.xml。我也認爲你的路徑變量需要以一個前導斜槓開始。我不知道它是否可以包含兩個級別,您可能只想將其更改爲path =/assets

接下來,查看您的context.xml文件。如果它說

<Context antiResourceLocking="true"> 

你需要在新文件可用之前重新加載上下文。如果您的Context元素沒有antiResourceLocking =「true」,那麼該文件應該立即可用。

可以以編程方式重新加載情況下,無需重新啓動Tomcat中,通過發出GET請求http://localhost:8080/manager/text/reload?path=/assets(假設你改變你的路徑變量/資產)

但是你可能需要提供一個Authenticator,這樣:

Authenticator.setDefault (new Authenticator() { 
     protected PasswordAuthentication getPasswordAuthentication() { 
      return new PasswordAuthentication ("tomcat", "password".toCharArray()); 
     } 
    }); 

    URL url = new URL("http://localhost:8080/manager/text/reload?path=/assets"); 

    try { 
     HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
     conn.setRequestMethod("GET"); 
     conn.getResponseCode(); 

     BufferedReader in = new BufferedReader(
       new InputStreamReader(conn.getInputStream())); 
     String inputLine; 
     StringBuffer response = new StringBuffer(); 

     while ((inputLine = in.readLine()) != null) { 
      response.append(inputLine); 
     } 

     logger.info(response.toString()); 
     in.close(); 

    } catch (Exception e) { 
     logger.error(e.getMessage(), e); 
    }