Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get application directory?

Status
Not open for further replies.

SuperMoonster

Programmer
Aug 11, 2005
59
0
0
BR
Hello guys,

I wanna get the directory from where my webapp is running. For desktop apps, I do:

Code:
System.getProperty("user.dir");

How do I do it for webapps? I wanna get the path, something like: /srv/
 
From a JSP or servlet :

String webappRoot = getServletContext().getRealPath("/");

will give you :

TOMCAT_HOME/webapps/YourWebApp

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Actually, I wanna do it from a Struts Action. Is there any way? Because it keeps giving me an error.
 
Take note : when asking a question, say EXACTLY what you want- be SPECIFIC. That way, you'll get quicker answers, and we won't be wasting our time.

Thanks.

In a struts action class then (the execute() method) :

String webappRoot = request.getSession().getServletContext().getRealPath("/");

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top