Welcome to Dream.In.Code
Click Here
Getting Java Help is Easy!

Join 118,887 Java Programmers for FREE! Ask your question and get quick answers from experts. There are 2,079 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



File upload servlet

 
Reply to this topicStart new topic

File upload servlet, deleting files after user has downloaded them

mihir83in
post 2 Jul, 2008 - 10:01 AM
Post #1


New D.I.C Head

*
Joined: 4 Jun, 2008
Posts: 13

Hi, greetings

I am developing a file upload servlet,
After parsing the files and doing all the processing,
I am giving back the links to the user to download the modified files.

I want to delete all the files that i have stored after the user has downloaded them, I have written a deleteFiles() function for that, but I dont know how to detect that the user has downloaded files , I want to know how to delete these files.

I tried finalize() method in servlet, but didnt work,

So please help ASAP
CODE

public void deleteFiles()
    {
       File files[] = baseurl.listFiles();
       for(File x:files)
           x.deleteOnExit();
       File parent = new File(baseurl.getParent());
       baseurl.deleteOnExit();
       files = parent.listFiles();
       for(File x:files)
           x.deleteOnExit();
       parent.deleteOnExit();
    }


and this is my doPost
CODE

public void doPost(HttpServletRequest request, HttpServletResponse response)
    {
        try
        {
            checkRequestAndInit(request, response);
            parseFormFields(request, response);
            if(eord.equals("e"))
                doEncrypt();
            if(eord.equals("d"))
                doDecrypt();
            deleteFiles();
        }
        catch(Exception  s) { pr.write("There was an error in servlet"); }
        finally { pr.close(); }
    }

User is offlineProfile CardPM

Go to the top of the page


Programmist
post 3 Jul, 2008 - 01:13 PM
Post #2


Four-letter word

Group Icon
Joined: 2 Jan, 2006
Posts: 1,175



Thanked 6 times

Dream Kudos: 100
My Contributions


Are the "links" you are passing the users static file references (e.g. http://www.myDomain.com/somefile.txt)? If so, then then the download is run in a completely separate connection (between the user's browser and your web server). In other words, it bypasses your servlet. If you want to be able to detect when the download completes then you will literally have to serve the file yourself, though your servlet. It's really not difficult. Check out this Sun Java Developer Forum post.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/13/08 03:16AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month