This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of TensorFlow 2.0 in Action and have Thushan Ganegedara on-line!
See this thread for details.
Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

writing a new file to the context root

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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?

Thanks,
Rakesh
 
Saloon Keeper
Posts: 6645
161
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
raki sugi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 22024
108
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim Moores
Saloon Keeper
Posts: 6645
161
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, a very simple one: web apps have no concept of a "default directory", so any relative path is basically undefined.
 
It's a tiny ad. At least, that's what she said.
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic