Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ServletContext#getRealPath("/") return a relative path?

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/...' , so getRealPath 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

like image 276
Jan Hoeve Avatar asked May 19 '26 23:05

Jan Hoeve


1 Answers

Something like

String path = new File(servletContext.getRealPath("/")).getAbsolutePath();

should solve your problem. (It does not answer your Question though...;-) )

Regards, Jan

like image 119
Jan Avatar answered May 21 '26 13:05

Jan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!