【问题标题】:Tomcat context docbaseTomcat 上下文文档库
【发布时间】:2016-05-13 05:28:04
【问题描述】:

我正在使用 tomcat 8,我有一个检索和更新个人资料图片的功能。这些文件位于外部文件夹中。在 servlet.xml 中使用此代码检索

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

它在我的本地 tomcat 中运行良好,但是在远程服务器中访问它时,没有显示新创建的文件。我必须重新启动服务器中的 tomcat 才能显示新图像。

我也试过了

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

但还是不行

任何想法如何不必重新启动 tomcat?

【问题讨论】:

  • “C:/assets”是链接吗?

标签: jsp tomcat tomcat8


【解决方案1】:

我相信您的 docBase 行属于 server.xml,而不是 servlet.xml。我还认为您的路径变量需要以斜杠开头。我不知道它是否可以包含两个级别,您可能只想将其更改为 path=/assets

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

<Context antiResourceLocking="true">

您需要在新文件可用之前重新加载上下文。如果您的 Context 元素没有 antiResourceLocking="true",那么该文件应该立即可用。

您可以通过向http://localhost:8080/manager/text/reload?path=/assets 发出 GET 请求以编程方式重新加载上下文,而无需重新启动 Tomcat(假设您将路径变量更改为 /assets)

但是您可能需要提供一个身份验证器,如下所示:

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);
    }

【讨论】:

    猜你喜欢
    • 2018-12-19
    • 2010-12-15
    • 2010-12-17
    • 2011-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-02
    • 2020-06-01
    相关资源
    最近更新 更多