tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jerry Ford <jf...@katzenjammer.us>
Subject writing a file from a servlet
Date Sun, 01 Feb 2004 23:12:10 GMT
I want to write a config file from a servlet implemented in 
/usr/local/webserver/tomcat/webapps/myWebapp/WEB-INF/classes/my/package/myWebapp.class, 
to a myWebapp/conf directory.  The directory exists, and there are no 
permissions issues---I can write the config file if I hardcode a full 
path to the file.

The following works:

FileWriter fwrite;

try
{
   fwrite = new File 
Writer("/usr/local/webserver/tomcat/webapps/myWebapp/conf/" + project + 
".conf");
   // ...etc.
}
catch(IOException e)
{
   // ...etc.
}

But if I change the path in the new FileWriter statement to any of the 
following, it does not work:

   /myWebapps/conf (relative to tomcat's servlets root)
   conf/ (relative to the docBase declared in the webapp's context)
   ../../../../conf (relative to the class file)

I get a FileNotFound...(No such file or directory) exception.

What does tomcat consider to be the relative path to the myWebapp/conf 
directory?  relative to what?

BTW, this is a private, internal app that won't be deployed in a public 
website, so there are no concerns about writing files to the server's 
disk.  But I want to reserve the option of deploying to a Windows 
machine or keeping it on the Linux box, and I don't want to be tied to a 
specific directory location on either box. 

Thanks.

Jerry


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message