Simon --

If the files you're reading and writing are truly temporary files, there's an attribute available from the ServletContext called javax.servlet.context.tempdir which provides a java.io.File object of a directory that is unique to the context your code is running in. So, for example,

String tdirAttr = "javax.servlet.context.tempdir";
File f = (File) getServletContext().getAttribute(tdirAttr);

will give you a container-controlled directory to which you can read and write to your hearts content.

Another option, depending on what you're trying to do, is to use the ServletContext.getRealPath() method. Calling getRealPath("/") will return the path to the root of your context (though this won't work if you're using packed webapps). Not generally considered best practice, but something to consider.

Hope that helps,
justin


At 06:00 AM 12/9/2002, you wrote:
I've just been looking at the URL package, but I can't see how that is going
to get around the directory problem?  I need the host to be transparent to
the servlet and the files to be always found from the web app location.  If
I start putting urls in, I will start to tie myself to specific locations.

Is there a way of getting the current URL path from the server without
writing it in explisitly.

Cheers

Simon

PS
Excuse the spelling, I've been at the for days now and I'm getting a little
tierd. ;-)

----- Original Message -----
From: "Laxmikanth M.S." <[EMAIL PROTECTED]>
To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Monday, December 09, 2002 12:55 PM
Subject: RE: File structure in webapps for tomcat.


> use class URI in java.net.* package.....
> no need to set in server.xml
>
> Regards
> Laxmikanth M S
> Off*  : 91-80-6610330 extn 1256
> Res* : 91-80-5267150
> http://www.sonata-software.com
>
> > Coming together is the beginning, staying together is progress and
working
> > together is Success
> What lies behind us and what lies before us are tiny matters compared to
> what lies within us  - Emerson
>
>
> > -----Original Message-----
> > From: Simon Kelly [SMTP:[EMAIL PROTECTED]]
> > Sent: Monday, December 09, 2002 5:23 PM
> > To: Tomcat Users List
> > Subject: File structure in webapps for tomcat.
> >
> > Hi,
> >
> > I am trying to get my servlet to write to and read from files within my
> > webapp structure.  However, when the servlet runs it seems that the
> > working
> > directory during its lifecycle is c:\xxx\tomcat 4.1.  Is there any way,
in
> > web.xml, to force the servlet to run in it's own app directory
structure?
> >
> > Regards
> >
> > Simon

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to