wood burning stoves 2.0*
The moose likes Servlets and the fly likes path of application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "path of application" Watch "path of application" New topic

path of application

raj baig
Ranch Hand

Joined: Jul 11, 2006
Posts: 96
hi all,

can you tell me how to get my complete path of web application.

like: c:\prog files\tomcat\webapp\myapp

how can i get this path in my servlet

thank you all.
Eddy Lee Sin Ti
Ranch Hand

Joined: Oct 06, 2005
Posts: 135
In your JSP, you can use application.getRealPath("/"). In your servlet, use the ServletContext.getRealPath("/").

One thing to note is that not all containers deploy your application by exploding them into certain directory. Some is using the WAR/EAR file as a whole.

SCJP, SCWCD, SCJWS, IBM 700,IBM 701, IBM 704, IBM 705, CA Clarity Technical<br /> <br /><a href="http://eddyleesinti.blogspot.com" target="_blank" rel="nofollow">http://eddyleesinti.blogspot.com</a>
raj baig
Ranch Hand

Joined: Jul 11, 2006
Posts: 96
in case of war file can you tell me how to achieve the path
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Depends what you want to do. If you want to write/edit files, it is not so easy. If you are looking to read from a file, you can (usually) use the ClassLoader to find an InputStream from files in the WAR/EAR
wood burning stoves
subject: path of application
Similar Threads
File reading from any path
How can I get application path from java code?
Directory creation in the server
Get absolute path using Java
migrate program from unix to windows, confuse about Path