tags:

views:

1274

answers:

1

Hi i am getting path of the context directory in my local system using..

String myfile = application.getRealPath("/");

but the method getRealPath("/") is returning null when application is deployed in war file in www.eatj.com.. can any one provide me possible solution and sample code please... The purpose is i have to create a xml file in my context directory... and each request i have to overwrite this xml file...

+2  A: 

This is what Javadoc says

Returns a String containing the real path for a given virtual path. For example, the path "/index.html" returns the absolute file path on the server's filesystem would be served by a request for "http://host/contextPath/index.html", where contextPath is the context path of this ServletContext..

The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, including the proper path separators. This method returns null if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a .war archive).

Bhushan