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
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Bhuvanesh MohankumarRank #310 · 8.1K reputationPosted Apr 11, 2017, 11:22 AM EDT
You basically need to convert the relative web path to absolute disk file system path by
ServletContext#getRealPath().String relativeWebPath = "/uploads"; String absoluteDiskPath = getServletContext().getRealPath(relativeWebPath); String filename = FilenameUtils.getName(item.getName()); File file = new File(absoluteDiskPath, filename); // ...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.