Hi, I need to access my drictory(s) on server in my tomcat application from servlets to list the files available in the drictory. Also, I need to upload files, for which I need to get the path too, but the method getServletContext().getRealPath("SomeDirectory") returns null. My application works perfectly fine under winodws, however, under fedora it returns null and it is installed as war file using tomcat. I can access other files in the same direcoty of war file. Please help me out. Here are some codes which I tested and the string path is always coming as null, althought getServletConfig() or getServletContext() are not null.
If you deploy by dropping the war file into TOMCAT/webapps, Tomcat will unpack the war file and run the app from an exploded file system (getRealPath will work). If you deploy a war file with the manager from a different location it will not.
I've often posted agains relying on getRealPath on this and the JSP forum. Doing so creates non-portable webapps. It's better to make the location of upload dirs, etc configurable with servlet or context init params (and keep the location outside of the webapp).
Hi, Thanks for the reply from everybody. I have tried even adding my application context name, that doesn't work too.
If we cannot access directories in war file using getRealPath.., do you know what changes to make in tomcat in fedora (linux) to make tomcat to explode the war file everytime new war file is uploaded, although my jsp pages are getting images and links for files under same directories in war file are working.
However, thanks for your help. I really appreciate. Thanks.
subject: getRealPath returns null in Linux(Fedora)