Why does ServletContext#getRealPath("/") return a relative path?
10,790
Something like
String path = new File(servletContext.getRealPath("/")).getAbsolutePath();
should solve your problem. (It does not answer your Question though...;-) )
Regards, Jan
Author by
Jan Hoeve
married, one child, java developer, broad technical interest
Updated on June 04, 2022Comments
-
Jan Hoeve almost 2 years
I have the following snippet of code:
String path = servletContext.getRealPath("/");
Now I got a bugreport from a user saying that the returned path is not an absolute path. The returned path is '
usr/local/...
' instead of '/usr/local/...'
, sogetRealPath
seems to be returning a relative path.I can see this, because the returned path is logged into a logfile.
My specs are:
- JBoss 4.0.5.GA
- Redhat EL 4
- jdk 1.5.0
See here for the javadoc