2016-05-13 38 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); 
    }