Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to store files in session?

 
Pete Neu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic