Setting "root" in Tomcat

Setting "root" in Tomcat

Post by trentschum » Sun, 14 Nov 2004 10:25:30


Hi,

I've installed Tomcat 4.1.31 on with JVM 1.4.2_04-b04 on a WinXP
machine.

In a JSP I have the following code to test where it allocates new
files:

File outputfile = new File("findme.txt");
outputfile.createNewFile();

When I run it, it creates the "findme.txt" file in:

C:\Documents and Settings\trent\Start Menu\Programs\Apache Tomcat 4.1

This seems to be an odd place, and I've scoured all the configuration
files, environment variables etc. to try to find where to set this to
a different directory.

Any suggestions?

Thanks!
Trent.
 
 
 

Setting "root" in Tomcat

Post by Wendy » Sun, 14 Nov 2004 11:58:04


The Servlet specification requires the container to provide you with a place
to write temporary files, check SRV.3.7.1 for full details. (Retrieve
context attribute javax.servlet.context.tempdir for the path.) Or create
your own context parameter in web.xml and specify a path, then use that to
place your files in a known location.

The problem with what you're doing is that as you've noticed, the file can
land in odd places depending on how and by what user Tomcat is started.
Server admins aren't going to be happy with you trying to write files all
over the place, and they may even have the directories marked read only so
you can't do it.

--
Wendy in Chandler, AZ

 
 
 

Setting "root" in Tomcat

Post by Suds » Sun, 14 Nov 2004 13:45:50


<snip>

Wendy is quite correct. Do investigate ServletContext#getRealPath, however.
Try this link (for 1.4 at least):
< http://www.yqcomputer.com/ #getRealPath(java.lang.String)>

--
Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.
 
 
 

Setting "root" in Tomcat

Post by trentschum » Wed, 17 Nov 2004 04:46:41


Thanks for the leads...Unfortunately I'm new to Tomcat XML config
files and "contexts" etc and so am still confused. I tried wading
through the JNDI stuff, but it didn't really tell me what I needed
either,although, from what I can gather, I think that JNDI might be
the way to go.

I'll muddle forward and figure it out!

Cheers,
Trent.
 
 
 

Setting "root" in Tomcat

Post by Oscar kin » Wed, 17 Nov 2004 06:45:12


Maybe. But in any case, try to think of it as "there is no default
directory". This is especially handy when writing log files.

Also, JNDI and/or web.xml are excellent places to put configuration
parameters that don't change during the application's lifetime.


--
Oscar Kind http://www.yqcomputer.com/
Software Developer for contact information, see website

PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2