Results 1 to 2 of 2
- 05-19-2010, 05:01 PM #1Member
- Join Date
- May 2010
- Rep Power
Which is the best place/way to create temp files using struts2
I am using Struts 2. And need to create temp files which needs to be streamed to the client browser. They will be deleted after send is successful.
Which is the best location to create such temp files? Of course, we can create them in session context, but I would like to know your views on this.
Also, Is there any struts2 way of getting temp files? The file handle should be available.
Thanks in advance,
- 05-21-2010, 02:31 AM #2
i think most servlet containers set the java environment variable for "java.io.tmpdir" and if not. perhaps the operating system default that will have been set from the java VM will suffice.
so you can do something like
String tmpdir = System.getProperty("java.io.tmpdir"); File myTmpFile = new File(tmpdir, "myFileName");
in a web server environment it is perhaps better to make use of the "File.createTempFile()" facility to have the file name generated with some amount of randomness so as to not have name clashes, and this automatically have the file placed into the java.io.tmpdir folder for you.
One other note, it might be hand to have the temporary files created for a given user added to some session variable (.e.g. Vector<File> myTemporaryFiles on the session attributes, and then have a SessionListener that looks for this variable when the session is being destroyed, and if there is a myTemporaryFiles item, and if it contains items, then for each item delete() it. This is because making use of the classical File.deleteOnExit() facility is not always appropriate for use in a web server environment, because the file is deleted only when the Java VM hosting the application server is restarted, which is typically much longer than the user's session, where we usually want to have any remaining temporary files deleted right.
- By Stephen Douglas in forum New To JavaReplies: 26Last Post: 03-26-2010, 05:50 PM
- By saqib15 in forum New To JavaReplies: 0Last Post: 02-17-2010, 07:16 PM
- By rummy in forum New To JavaReplies: 3Last Post: 02-11-2010, 02:08 AM
- By aiancu in forum EclipseReplies: 0Last Post: 04-21-2009, 04:58 PM
- By ramesh.8189 in forum AWT / SwingReplies: 4Last Post: 02-12-2009, 08:59 AM