wants store the files in database and retrieve files
i want to upload the files to the database and uploaded files should come under tree strctured folders and sub folders using jsp servlet codes. right now my files are saving in localhost server
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bhuvanesh MohankumarPosted Apr 11, 2017, 3:22 PM
You basically need to convert the relative web path to absolute disk file system path by
ServletContext#getRealPath().However, this approach of writing uploaded files to expanded WAR folder is absolutely not recommended. When you redeploy the WAR, all those uploaded files will get lost (simply because they are not contained in the original WAR!). It will also not work when the server is configured to expand WAR in memory instead of on disk. The
getRealPath()would then returnnull.Write uploaded files to a path outside the expanded WAR folder. You did it right at first place. You can always make the upload folder configureable by specifying it as a VM argument or a properties file setting.