my dog learned polymorphism*
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 Android Security Essentials Live Lessons this week in the Android 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?!
 
 
subject: Application root
 
Similar Threads
setting index.html to my context root
JSP and JavaBeans
Is WEB-INF Directory mandatory ?
tomcat incommunicado
servlet configuration problem