【发布时间】: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