This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes ServletContext.getRealPath() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "ServletContext.getRealPath()" Watch "ServletContext.getRealPath()" New topic
Author

ServletContext.getRealPath()

Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
Hi,
May I know whether the following is true?
ServletContext.getRealPath(anyPath) is equivalent to ServletContext.getRealPath("/") + anyPath?
Thanks!
sridhar satuloori
Ranch Hand

Joined: Nov 05, 2001
Posts: 144
getRealPath returns the "real path" for a given virtual path. Real path is system dependent
Ro answer your question. mostly No. ie, if "/" and all ur "anyPath(s)" maps to the same physical component you will get the same real Path. but in usage we map different paths to difeerent components on the system, in this type you never gets the same value for "/" and anypath.
Sridhar

Originally posted by Meng Tan:
Hi,
May I know whether the following is true?
ServletContext.getRealPath(anyPath) is equivalent to ServletContext.getRealPath("/") + anyPath?
Thanks!

Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
Hi sridhar,
Why ServletContext.getRealPath("/servlet/MyServlet") does not give me the actual file system path i.e. "c:\tomcat\webapps\MyContext\WEB-INF\classes\MyServlet.class" instead it gives "c:\tomcat\webapps\MyContext\servlet\MyServlet"?
Thanks.
Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
I m using Tomcat as my web server and I also have a servlet called MyServlet in "c:\tomcat\webapps\MyContext\WEB-INF\classes.
But when i call getServletContext().getRealPath("/servlet/MyServlet"), it does not return me the actual file system path which is "c:\tomcat\webapps\MyContext\WEB-INF\classes\MyServlet.class". Instead it gives me "c:\tomcat\webapps\MyContext\servlet\MyServlet".
Can someone help me?
Thanks.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: ServletContext.getRealPath()
 
Similar Threads
getting the contextpath to read and write text files
Get Host appbase Path of a JSP in Tomcat
relative path problem
How to specify the place from file which is going tobe read
Path to config file