Howdy,
A servlet container is required to supply your application with a
directory where you can run temporary files.  This directory is
available via
File tempDir = (File)
getServletContext().getAttribute("javax.servlet.context.tempdir");

You'd know the above if you'd read the servlet specification, but I'm
getting tired of that mantra ;)

Then you can say:
File myTempFile = File.createTempFile("prefix.", ".suffix", tempDir);
// Use a FileWriter or whatever to write your file

// Stream or link this temp file's contents back to the browser
// Stream via FileReader,
// or directly link file File.toURI().toURL(), or whatever method you
want

You can then delete the file if you want.

Yoav Shapira
Millennium ChemInformatics


>-----Original Message-----
>From: Jason Viers [mailto:[EMAIL PROTECTED]
>Sent: Thursday, October 16, 2003 9:13 PM
>To: Tomcat Users List
>Subject: Re: Writing temporary file & downloading it?
>
>Running Tomcat 4.1.27, I'm currently deploying via the "install" task
in
>the Ant script supplied with Tomcat, so all my files reside outside of
>the Tomcat directory.  Otherwise, everything's pretty normal (Tomcat
>resides in C:\tomcat).
>
>Just for curiosity's sake, could I find out what methods there are
>(instead of only what someone thinks is best?).  6 months down the road
>my situation might change (this is still in development & real
>deployment might be different) and it'd be nice to know what my options
>are.  Suggestions for which method is best are of course still welcome.
>
>Thanks
>Jason
>
>Justin Ruthenbeck wrote:
>
>>
>> Yes, it is possible.  Give us an idea of your deployment setup (are
>> you deploying as a .war file?  Using default root paths?  Anything
>> special?) and we can suggest the best way to go about doing it.
>>
>> justin
>>
>> At 04:16 PM 10/16/2003, you wrote:
>>
>>> Is it possible, in a servlet, to write to a temporary file in a
>>> location that I would then be able to link to so the users can
>>> download?  I couldn't find any information indicating either way.
>>>
>>> Thanks
>>> Jason
>>>
>>>
>>>
>>>
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>> ____________________________________
>> Justin Ruthenbeck
>> Software Engineer, NextEngine Inc.
>> justinr - AT - nextengine DOT com
>> Confidential
>>    See http://www.nextengine.com/confidentiality.php
>> ____________________________________
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]




This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


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

Reply via email to