Setting "root" in Tomcat

2

2kuser

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.
 
W

Wendy S

2kuser said:
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?

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.
 
S

Sudsy

Wendy said:
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 is quite correct. Do investigate ServletContext#getRealPath, however.
Try this link (for 1.4 at least):
<http://java.sun.com/j2ee/1.4/docs/a...letContext.html#getRealPath(java.lang.String)>
 
2

2kuser

Sudsy said:
Wendy is quite correct. Do investigate ServletContext#getRealPath, however.
Try this link (for 1.4 at least):
<http://java.sun.com/j2ee/1.4/docs/a...letContext.html#getRealPath(java.lang.String)>


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.
 
O

Oscar kind

2kuser said:
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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top