【问题标题】:jsp how to creat a log.txt file in openshiftjsp如何在openshift中创建log.txt文件
【发布时间】:2016-07-09 12:20:53
【问题描述】:

我需要在 log.txt 文件中为每个请求保存一些内容。

下面的 index.jsp 正确地做到了(在 localhost 中运行)。

StringBuilder html =  new StringBuilder();
ServletContext context = request.getServletContext();
        String file = context.getRealPath("/");
        html.append(html);
        file += "log.txt";
        System.out.println(file);
        html.append("<br/>\n____________________________________<br/>\n");//file path
        html.append(file.toString());//file path
        html.append("<br/>\n____________________________________<br/>\n");//file path

        FileWriter filewriter = new FileWriter(file, true);
        filewriter.write(html.toString());
        filewriter.close();

但是当我在 Openshift 中推送我的项目时,它返回 null 作为文件路径: 我手动创建 log.txt 并在 index.jsp 附近为其权限设置了 777 但它始终为空!!

【问题讨论】:

    标签: java jsp tomcat7 openshift


    【解决方案1】:

    根据开发者中心[1],如果您想永久存储上传/动态创建的文件,您应该使用data 文件夹。否则每次执行 git push 时它们都会被擦除。

    【讨论】:

    • 你的权利,但是如何在那里创建文件?我尝试在 /data 中创建文件,但它有一些错误!??我可以有任何代码吗?
    猜你喜欢
    • 2015-10-13
    • 1970-01-01
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 2016-07-11
    • 2016-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多