0

I'm writing a website with the function file uploading. And the Path I save the file is by 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

the function is ok. But when it comes to redeploy on tomcat here comes the problem.

When I redeploy by war file. It seems sorts of remove the all webapps/mywebsit. And deploy it with the 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? Or I should store files outside the webapps? But how can I let client be able to reach the file?

Pravin
  • 1,137
  • 12
  • 20
JackSie
  • 87
  • 2
  • 10
  • Files should be stored outside of the web application root. – Pavel Horal Nov 20 '14 at 12:10
  • possible duplicate of [Where/how to store persistent data with tomcat?](http://stackoverflow.com/questions/1792634/where-how-to-store-persistent-data-with-tomcat) – Aleksandr M Nov 20 '14 at 12:11
  • 1
    it only duplicates part of that task. **Note**: Beside having your files stored in a proper directory of your web- or application-server that are accessible by users there are other possibilities like mapping the URL part 'XXXXX' to a local file path on the server only the webapp has read-access to - then provide the file as Download from a Servlet or print its content as webpage. – JBA Nov 20 '14 at 12:15
  • Thank you. I've solved the problem by the method from #user1902288 – JackSie Nov 20 '14 at 13:52

1 Answers1

1

When tomcat redeploys your application, it will remove it's directory under /webapps/ completely and unpack the WAR from scratch. TI'd recommend keeping your files outside the webapp's directory. 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.