tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jerry Ford <>
Subject writing a file from a servlet
Date Sun, 01 Feb 2004 23:32:58 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;

    fwrite = new 
FileWriter("/usr/local/webserver/tomcat/webapps/myWebapp/conf/" + 
project + ".conf");
  // ...etc.

But if I change the path 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.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message