I searched around the web and here and couldn’t find a conclusive answer to this rather simple question. I am using Java+MySQL+HTML and CSS.
I created a webapp, and in this webapp the user can upload the photos path to the database .At the same time I am creating a folder completely outside of tomcat to copy inserted images there. The folder is on my desktop as I am on localhost, but I want to make the storage on the server not on my desktop.
After checking stackoverflow I saw that it is bad to store photos/images in tomcats webapp/AppName folder because this will overwrite the images all the time at redeployment which I don’t want to do.
My tomcat folder is on desktop. Can I create a folder to store the images for this specific app here:
DesktopApacheTomcatapache-tomcat-9.0.24 ?
The folder would be called TripAppImages like DesktopApacheTomcatapache-tomcat-9.0.24TripAppImages and will be besides all of tomcats other folders like bin, conf, etc. I will also use this folder to display the images that the user inserted , back to him in a html page.
EDIT: ok so I have finally come upon a message from here how to create a folder in tomcat webserver using java program? from BalusC which says:
“Please note that you shouldn’t store the files in the expanded WAR folder, or they will get lost every time you redeploy the webapp. Store them on a fixed path outside Tomcat’s /webapps folder.”
This I believe means that I can store the images like this DesktopApacheTomcatapache-tomcat-9.0.24TripAppImages. As long ass they are not in the webapp folder it means they won’t be overwritten.
Advertisement
Answer
The only folders you should avoid are temp
, webapp
, work
and its subfolders, because yes, those folders can have its content replaced or deleted during deploys and cleanings, every other folder inside tomcat can be considered as ‘just a folder’ that, if you don’t modify its contents, you can use the way you want. Of course it would not be normal or standard to, for example, store videos inside Tomcatbin
but if you don’t touch the original files there you can do it.
So technically speaking, you can create a folder like DesktopApacheTomcatapache-tomcat-9.0.24icecream
and put images there it will not be erased or replaced by a deploy.
If it is just for you, temporary or not production
, just avoid the three folders mentioned at the beginning and you are good to go.