GeeCON Prague 2014*
The moose likes Tomcat and the fly likes Location for uploaded files in Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Tomcat
Bookmark "Location for uploaded files in Tomcat" Watch "Location for uploaded files in Tomcat" New topic
Author

Location for uploaded files in Tomcat

Tony Walters
Ranch Hand

Joined: Feb 13, 2003
Posts: 54
I'm uploading some files to Tomcat via a webapp. I was surprised to find the default location was to store uploaded files in the bin directory. Is there a uploaded file location specified for all J2EE-compliant JPS/Servlet containers, and how do I get it?

Advice gratefully received.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
If you are saving files in a way that depends on the "current" directory, there is no way of telling where they will end up. You must use code that controls the complete file path.
Bill
Tony Walters
Ranch Hand

Joined: Feb 13, 2003
Posts: 54
If I do that, the system won't be portable to another app server, or another computer. At the very least this system will at some point be on a production server, rather than a dev one.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
1. you can make the path to the file storage directory a configurable parameter in web.xml with init-param tags. Convenient for user configuration.
2. you can make the path an environment variable
3. you can make the path relative to the web app installation - see ServleContext.getRealPath()
4. etc. plenty of other possibilities.....
Bill
 
GeeCON Prague 2014
 
subject: Location for uploaded files in Tomcat