Meaningless Drivel is fun!
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
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="" target="_blank" rel="nofollow"></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
I agree. Here's the link:
subject: path of application
It's not a secret anymore!