getting the disk absolute path of a web-app

Y

yair

hey all
in a servlet running in tomcat, how can i get the full path of my web
application on the disk (something like "c:\progran
files\tomcat\webapps\myApp")?
i don't want to write it in the web.xml or to pass it as a system
property.
thanks
yair
 
A

Andrew Thompson

how can i get the full path of my web
application on the disk (something like "c:\progran
files\tomcat\webapps\myApp")?

javax.servlet.ServletContext.getRealPath(java.lang.String)

HTH
 
W

Will Hartung

Andrew Thompson said:
javax.servlet.ServletContext.getRealPath(java.lang.String)

However, this is not guaranteed to not return null. If, for example, your
web-app is running from an unexploded WAR file, you won't get a useable
value.

Regards,

Will Hartung
([email protected])
 
J

Juha Laiho

(e-mail address removed) (yair) said:
in a servlet running in tomcat, how can i get the full path of my web
application on the disk (something like "c:\progran
files\tomcat\webapps\myApp")?
i don't want to write it in the web.xml or to pass it as a system
property.

Adding to the response by Will Hartung; for what would you need this;
what would you do with the information? Once we know that, we may be
able to propose alternative ways of solving the problem.
 
Y

yair

Juha Laiho said:
(e-mail address removed) (yair) said:

Adding to the response by Will Hartung; for what would you need this;
what would you do with the information? Once we know that, we may be
able to propose alternative ways of solving the problem.

thanks for u're answer first.

i will have a folder named "tests" under webapps/myApp, and i want to
read the names of the files in this folder. i m going to show the user
a page with the names of those files and let him choose a file to run
(this ofcourse is a very simplified version of what i m trying to do).
this webapp will not be JAR-ed, so i dont have a problem with that.

it seems like:
javax.servlet.ServletContext.getRealPath("")
or
javax.servlet.ServletContext.getRealPath("/")
r working fine, i think i'll use this way.
thanks
yair
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top