我有使用tomcat的 ..this是我的目录结构中的两个web项目上传文件..创建文件夹,使用的servlet
webapps
--project1
--WEB-INF
--project2
--WEB-INF
我使用commons-fileupload..this是部分我在代码servlet的在PROJECT1
String fileName = item.getName();
String root = getServletContext().getRealPath("/");
File path = new File(root + "/uploads");
if (!path.exists()) {
path.mkdirs();
}
File uploadedFile = new File(path + File.separator + fileName);
item.write(uploadedFile);
这将在“PROJECT1”创建“上传”文件夹,但我想在“web应用”打造“上传”文件夹,因为我不想“上传”文件夹不见了,当我取消部署“PROJECT1” ..
我已经尝试String root = System.getProperty("catalina.base");
但不会工作。
谁能帮我...在此先感谢
为什么不在你的服务器的另一个路径中创建'upload'文件夹,而是给所有t他允许tomcat用户读/写文件到该文件夹? –
@LuiggiMendoza你可以用代码解释..实际上,我已经尝试在webapps中手动创建'upload'文件夹并使用 File uploadedFile = new File(“http:// localhost/upload /”+ fileName); item.write(uploadedFile); 但不工作 – nat