aspose file tools*
The moose likes Servlets and the fly likes Retrieving Server Path Programmatically 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 "Retrieving Server Path Programmatically" Watch "Retrieving Server Path Programmatically" New topic
Author

Retrieving Server Path Programmatically

James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
Hi,
I am using Tomcat as my web server.
My project is in c:\tomcat\webapps\myproject
Is there a way to retrieve the project path (which is the path above) from either the servlet or bean?
I tried using ServletContext.getRealPath(Str) but I need to provide a String a location in returns.
I had even tried System.getProperty("user.dir") but it gives me the c:\tomcat\bin

Thanks in advance.
prabhat kumar
Ranch Hand

Joined: Apr 11, 2001
Posts: 114
it is simple ..
use
getServletContext().getRealPath("/") ;
James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
Hi,
Tried the above suggestion and what I get is this:
C:\tomcat\bin\..\webapps\MyProject\
Not sure why I got the "bin\..\" part.

Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Retrieving Server Path Programmatically