Results 1 to 2 of 2
  1. #1
    Join Date
    May 2010
    Rep Power

    Default 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

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Rep Power


    i think most servlet containers set the java environment variable for "" 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
    Java Code:
    String tmpdir = System.getProperty("");
    File myTmpFile = new File(tmpdir, "myFileName");
    and this will compute the path to myFileName within the designated temporary folder.

    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 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

  1. Where to place the jar files..?
    By Stephen Douglas in forum New To Java
    Replies: 26
    Last Post: 03-26-2010, 05:50 PM
  2. Compare Array and setting to temp
    By saqib15 in forum New To Java
    Replies: 0
    Last Post: 02-17-2010, 07:16 PM
  3. Where to place jar files
    By rummy in forum New To Java
    Replies: 3
    Last Post: 02-11-2010, 02:08 AM
  4. Eclipse debug when ant uses temp files
    By aiancu in forum Eclipse
    Replies: 0
    Last Post: 04-21-2009, 04:58 PM
  5. How To Place Three Files In A Folder
    By ramesh.8189 in forum AWT / Swing
    Replies: 4
    Last Post: 02-12-2009, 08:59 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts