Setting "root" in Tomcat

Discussion in 'Java' started by 2kuser, Nov 13, 2004.

  1. 2kuser

    2kuser Guest

    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.
     
    2kuser, Nov 13, 2004
    #1
    1. Advertising

  2. 2kuser

    Wendy S Guest

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

    --
    Wendy in Chandler, AZ
     
    Wendy S, Nov 13, 2004
    #2
    1. Advertising

  3. 2kuser

    Sudsy Guest

    Wendy S wrote:
    > "2kuser" <> wrote:

    <snip>
    > 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/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)>

    --
    Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.
     
    Sudsy, Nov 13, 2004
    #3
  4. 2kuser

    2kuser Guest

    Sudsy <> wrote in message news:<>...
    > Wendy S wrote:
    > > "2kuser" <> wrote:

    > <snip>
    > > 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/api/javax/servlet/ServletContext.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.
     
    2kuser, Nov 15, 2004
    #4
  5. 2kuser

    Oscar kind Guest

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


    --
    Oscar Kind http://home.hccnet.nl/okind/
    Software Developer for contact information, see website

    PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
     
    Oscar kind, Nov 15, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,241
  2. Rick Osborn
    Replies:
    10
    Views:
    3,959
    Jon A. Cruz
    Feb 8, 2004
  3. CJ
    Replies:
    1
    Views:
    1,574
    Andrew Thompson
    Oct 29, 2004
  4. Sean Berry
    Replies:
    3
    Views:
    4,556
    Tim Terry
    Dec 19, 2005
  5. hector
    Replies:
    5
    Views:
    413
    CBFalconer
    Dec 5, 2006
Loading...

Share This Page