This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving Server Path Programmatically

 
James Gordon
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is simple ..
use
getServletContext().getRealPath("/") ;
 
James Gordon
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic