File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "Retrieving Server Path Programmatically" Watch "Retrieving Server Path Programmatically" New topic

Retrieving Server Path Programmatically

James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
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 ..
getServletContext().getRealPath("/") ;
James Gordon
Ranch Hand

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

I agree. Here's the link:
subject: Retrieving Server Path Programmatically
It's not a secret anymore!