简体   繁体   English

Tomcat重新部署时,以前的上传文件丢失

[英]When tomcat redeploy, the previous upload files are missing

I'm writing a website with the function file uploading. 我正在写一个上传功能文件的网站。 And the Path I save the file is by ServletActionContext.getServletContext().getRealPath("xxxx") 我保存文件的路径是ServletActionContext.getServletContext().getRealPath("xxxx")

It will save the file to webapps/mywebsit/xxxx to allow the clients are able to access the data directly by http:// mywebsit/mebsite/xxxxx 它将文件保存到webapps/mywebsit/xxxx以允许客户端能够通过http:// mywebsit/mebsite/xxxxx直接访问数据。

the function is ok. 功能还可以。 But when it comes to redeploy on tomcat here comes the problem. 但是,当要重新部署tomcat时,就会出现问题。

When I redeploy by war file . 当我按war file重新部署时。 It seems sorts of remove the all webapps/mywebsit . 似乎删除了所有webapps/mywebsit And deploy it with the new war file . 并用new war file部署它。 And the previous upload files are missing. 并且以前的上传文件丢失。

Is there anyway I can let tomcat don't remove my file while it's redeploying? 无论如何,我可以让tomcat在重新部署文件时不要删除我的文件吗? Or I should store files outside the webapps? 或者我应该将文件存储在Webapp之外? But how can I let client be able to reach the file? 但是如何让客户端可以访问文件?

When tomcat redeploys your application, it will remove it's directory under /webapps/ completely and unpack the WAR from scratch. 当tomcat重新部署您的应用程序时,它将完全删除/ webapps /下的目录,并从头开始解压缩WAR。 TI'd recommend keeping your files outside the webapp's directory. TI建议将文件保存在webapp目录之外。 You could try using environment variables to point your application to directory you'd like to use, taking care that the user tomcat runs under has appropriate access rights. 您可以尝试使用环境变量将您的应用程序指向您要使用的目录,请注意运行的用户tomcat具有适当的访问权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM