aspose file tools*
The moose likes Servlets and the fly likes ServletContext.getRealPath() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: ServletContext.getRealPath()