getServletContext().getRealPath problem

Dear all,

I have the following servlet, but when I call getServletContext().getRealPath("/WEB-INF/data/data.txt"), it always return null. I am using Tomcat 4.0 to deploy my web application. I've also tried to use getServletContext().getRealPath("index.html"), which also returns null. Any one has an idea for this?

publicclass ServletTestextends HttpServlet{

private String fileName ;

publicvoid init()throws UnavailableException{

this.fileName = getServletContext().getRealPath(

"/WEB-INF/data/data.txt");

}

protectedvoid doGet(HttpServletRequest request,

HttpServletResponse response)

throws IOException, ServletException

{

response.setContentType("text/html");

System.out.println("fileName" + this.fileName);

}

}

Many thanks!

[1403 byte] By [RichardLee1] at [2007-9-27 19:59:51]
# 1
Method getRealPath("/context") retreives the full path to the virtual directory described in Tomcat server.xml file under <Context>...</Context>.
citcru at 2007-7-6 23:47:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
> this.fileName = getServletContext().getRealPath("/WEB-INF/data/data.txt");Try with,this.fileName = getServletContext().getRealPath("/your_application/web-inf/data/data.txt");
sudha_mp at 2007-7-6 23:47:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...