Results 1 to 2 of 2
- 05-19-2010, 04:01 PM #1
Member
- Join Date
- May 2010
- Posts
- 1
- Rep Power
- 0
Which is the best place/way to create temp files using struts2
Hi All,
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,
~Abhay Dandekar
- 05-21-2010, 01: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
and this will compute the path to myFileName within the designated temporary folder.Java Code: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.
Similar Threads
-
Where to place the jar files..?
By Stephen Douglas in forum New To JavaReplies: 26Last Post: 03-26-2010, 04:50 PM -
Compare Array and setting to temp
By saqib15 in forum New To JavaReplies: 0Last Post: 02-17-2010, 06:16 PM -
Where to place jar files
By rummy in forum New To JavaReplies: 3Last Post: 02-11-2010, 01:08 AM -
Eclipse debug when ant uses temp files
By aiancu in forum EclipseReplies: 0Last Post: 04-21-2009, 03:58 PM -
How To Place Three Files In A Folder
By ramesh.8189 in forum AWT / SwingReplies: 4Last Post: 02-12-2009, 07:59 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks