Tomcat用于创建新文件的实际路径 [英] Tomcat actual path for new file creation

查看:74
本文介绍了Tomcat用于创建新文件的实际路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在JSP页面中创建一个仅给出名称的新文件,则该文件是在TOMCAT文件夹的/bin目录中创建的,而不是在.jsp的同一文件夹中创建的.

If in a JSP page I create a new file only giving it's name, it's created in the /bin directory of TOMCAT folder, rather in the same folder of the .jsp.

我不确定为什么会发生这种情况,似乎不太直观.

I'm not sure why this happens, seems to be not intuitive.

推荐答案

这绝对是直观的,因为正在运行的进程的当前目录是bin文件夹.

It's definitely intuitive, as the current directory of the running process is the bin folder.

您可以尝试以下操作:

ServletContext context = session.getServletContext();
String realContextPath = context.getRealPath(request.getContextPath()); 

这篇关于Tomcat用于创建新文件的实际路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆