I am debugging some old code and it has a File upload mechanism. The uploaded file is temporarily stored in the server. But the problem I am facing is, the file gets written to Tomcat_Home/bin folder. I want to change this and write to the context root. How do I do this?
The code probably uses relative paths; you should never do that in a web app. Use an absolute path that points to a location within your web app, or -even better- a location outside of the Tomcat directory.
posted 7 years ago
Thanks Tim. Yes, it does use relative path to create a file.
But is there any reason why relative paths in webapps are not recommended?
Because you never know what the current directory is that they will be relative to. That's why you should always use absolute paths. To turn a relative (to the web application) path into an absolute path you should use ServletContext.getRealPath.