我需要将每个请求的内容保存在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,但它始终为空!
根据开发人员中心[1]的说明,data
如果要永久存储上载/动态创建的文件,则应使用该文件夹。否则,每当您执行git push时,它们就会被擦除。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句