This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Servlets and the fly likes Application root Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Application root" Watch "Application root" New topic
Author

Application root

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hello there!
How can I figure out programmatically the application root?
I have the page
http://localhost/test
located at
c:\tomcat\webapps\test
Now can I programmatically get c:\tomcat\webapps\test out from http://localhost/test (or preferrably plain test)?
The example is tomcat, but I would like to see a solution where it does not matter whether container is WebLogic, Jetty or sum else...
Thx in advance!
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
This was easy:
getServletConfig().getServletContext().getRealPath("/")
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Originally posted by Antti Barck:
This was easy:
getServletConfig().getServletContext().getRealPath("/")

It seems that this approach fails when app is in .war?!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Application root