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

I have the following code snippet:

String path = servletContext.getRealPath("/");

Now I have an error from a user saying that the returned path is not an absolute path. The return path is " usr/local/..." instead of " /usr/local/...'", so getRealPathit seems to return a relative path.

I see this because the return path is written to the log file.

My specifications:

  • JBoss 4.0.5.GA
  • Redhat EL 4
  • jdk 1.5.0

See here for javadoc

+3
source share
1 answer

Sort of

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

should solve your problem. (He does not answer your question, though ... ;-))

Regards, Yang

+1

Source: https://habr.com/ru/post/1717367/


All Articles