I deployed my webapp in Tomcat, but when I prefix the filename with \ I end up in the root of my server (C) folder, and if I don't prefix it with \ I end up in the bin folder.
The former I expected, the latter I didn't.
What's the cleanest way to write to a folder in my webapp(userControlWebApp\images) because just doing ..\webapps\ + request.getContextPath() doesn't seem the cleanest way.
-
Can't you use an absolute path?Shervin Asgari– Shervin Asgari2011-01-06 12:34:22 +00:00Commented Jan 6, 2011 at 12:34
-
That's well so absolute... I like to keep it a bit dynamic.jack– jack2011-01-06 12:36:27 +00:00Commented Jan 6, 2011 at 12:36
Add a comment
|
1 Answer
Use getServletContext().getRealPath(..)
3 Comments
jack
Can't believe I forgot that one. Just tried System.getProperty("user.dir") and that also seems to work. Any reason to use one over the other?
Bozho
prefer the API - getRealPath. I'm not sure if the other is guaranteed to work always.
BalusC
Note that the folder and all its contents will get lost whenever you redeploy the webapp. It's not a good choice if you want to make it permanent. See also this related question stackoverflow.com/questions/4548190/…