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 Mon, 02 Feb 2004 02:00:04 GMT
 From a servlet implemented in
tomcat/webapps/myWebapp/WEB-INF/classes/my/package/myWebapp.class, I am
trying to write a config file to the directory myWebapp/conf.   The conf
directory does exist; and there are no permissions issues---I can write
the file to the conf directory from the servlet if I hardcode the full
path.

The following code works:

FileWriter fwrite;

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

But if I change the path in fwrite = new FileWriter() to
../../../../conf/ (making it relative to the class file) or to
/myWebapp/conf/ (relative to tomcat's servlets root; with or without the
leading /) or to conf/ (relative to the myWebapp directory, which is the
docBase declared in the context element in server.xml), I get a
FileNotFound (No such file or directory) exception.

How do I make the path relative to the servlet, so I don't have to hard
code the path?

The app won't be deployed on a public web server, so writing a file to
the server is not a problem, though I would like to have some
flexibility about where things get deployed---may end up on a Windows
machine, may stay on the Linux box.  But I want to make that decision
external to the code.

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