*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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