tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Specifying relative path for TOMCAT 5.5 ?
Date Thu, 01 Mar 2007 16:05:03 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Peter,

Peter Crowther wrote:
>> From: Rajendra Sakpal [mailto:rajendrasakpal.mailinglist@gmail.com] 
>> What is the right way to make Tomcat write a file in the directory
>> : "/webapps/Jonathon/WEB-INF/etc/subscriber.txt" ?
> 
> Use servletContext.getRealPath("/WEB-INF/etc/subscriber.txt").  However,
> you should not be writing files in your webapp directory; you are not
> guaranteed write access to it by the servlet spec.  For example, your
> webapp may not be unpacked, so the WEB-INF directory is inside the .war
> file.

IIRC, ServletContext.getRealPath("/WEB-INF/...") won't give you a usable
path if the webapp is in an unexploded WAR file, right? It would be
better to use ServletContext.getResource("/...") would be a better
method to use, as you'll get a URL from which you might be able to at
least /read/. (I realize that the OP was asking about writing).

> If you need to persist data, write to a database or (if you have
> to) write to some filestore that you define via a configuration option
> somewhere.

I completely agree.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5vmu9CaO5/Lv0PARAlcKAJ9HB+90zmUQ4T7k8i5ZZPJKae4dGQCeM1U8
CPED/JRth11ZkreVW6Sx+9w=
=tmad
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message