I have a form in my struts application which when submitted goes to a preview page. All the fields in the form are displayed in preview page. And the data is written only after confirm button in pressed in preview form.
Now, the problem: In the form there are file fields for uploading image. I want to display these images in the preview form. As I said I want the data to be written to db only after response in preview page. How do I go about it??? Can I do it without introducing another bean?(the form bean is already in session) I am also concerned about the size of the form bean in session when images are included. Should i change my approach???
One possibility would be to write the images immediately as a BLOB to the database in a temporary table, and then move it to the permanent table after the confirmation panel. That way you don't have to keep the images in the session. Images can be quite large, and putting that much data in an HttpSession is not recommended. [ August 05, 2006: Message edited by: Merrill Higginson ]
Hi Merill I too considered keeping it in a temporary table. One problem with this approach, though not very serious one, is that the images remain in db for sessions which expires prematurely due to causes like session timeout. In time these images will take a lot of space. How can I clear these images when session expires? [ August 05, 2006: Message edited by: azhar bharat ]
Joined: Feb 15, 2005
If you are using a container that implments servlet 2.3 or above, you can write an application event listener to handle this.
Here is a link that explains a bit about how to write them. Basically, you can register an event listener that will fire any time a session is about to expire. In this class you could then clean up whatever temporary data was created during that session.