wood burning stoves 2.0*
The moose likes Servlets and the fly likes How to store files in session? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to store files in session?" Watch "How to store files in session?" New topic
Author

How to store files in session?

Pete Neu
Ranch Hand

Joined: Feb 18, 2005
Posts: 86
Hello,

in my webapp I need to provide data in serveral formats for download: excel, xml and pdf. The question is: after I have generated these documents where do I store them? Should I save them on the local filesystem or is there a way to store the documents in the session?

cheers,

Pete
Balan Raj
Ranch Hand

Joined: Aug 26, 2003
Posts: 74
If u have large chunks of information, I would recommend retrieving them fresh each time they need to print the report.

Saving large amount of data in your session doesnt seem wise unless you need it repetedly all over the application.
Pete Neu
Ranch Hand

Joined: Feb 18, 2005
Posts: 86
I agree it's not good to keep the files longer than needed. But the point is how can I provide them just in time? First I do need to generate them and afterwards I need to provide a URL where the files are located on the filesystem. Is there any other way around this?
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
Storing files in local file system isn't so bad idea, however you should consider the following:
1. cleanup files after usage or server crash.
2. keep files until persistent session keeps reference to them
3. share files in clustering configuration, when session can migrate from one to another box


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
First I do need to generate them and afterwards I need to provide a URL where the files are located on the filesystem. Is there any other way around this?

You could write the "file" to a ByteArrayOutputStream and save a reference to the final byte[] in the session. The servlet responding to the request for that URL would grab the byte[] and write it to the output stream.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to store files in session?