Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_java_server thread: Getting full path from a bean


Message #1 by "Massimo LoVoi" <mlv@s...> on Sat, 31 Aug 2002 00:50:52
I need to get the full path to a dir on my UNIX server running Tomcat.
This has to be done inside a bean, not jsp or servlet.
I've tried: 
 File f = new File("");
 String apath = f.getAbsolutePath();
and all I'm getting is the full path up to my tomcat bin plus my relative 
path.

I've also tried using getServletContext like following 
public class UojTestNo extends HttpServlet {
 ...
 public String getPath()
 {
  String MyRelativePath="mypath";
  ServletContext ctx = getServletContext();
  String path = ctx.getRealPath("/" + MyRelativePath);
  return path
 }
 ...
}
but I get a java.lang.NullPointerException at the getServletContext()
What I am doing wrong?
Thanks
Massimo

  Return to Index