Lax
Lax

Reputation: 35

delete file when user close the browser in java

I want to delete file from server when browser closed at client side.

I have a requirement to save a an XML file and the same page will be reloaded using same XML after clicking submit button. To reload the same page JSP require the previously saved file. But I need to delete that file when it’s not required, is it possible to delete the file when browser closed, as I am not supposed to use sessions, how to find when user is closed the browser. I am using Spring MVC framework.

Please give me any idea how can I solve this.

Upvotes: 0

Views: 974

Answers (1)

c.pramod
c.pramod

Reputation: 606

You can use Ajax to make this possible :

1:Check if user wants to exit the window 
2: if yes then make Synchronous ajax call to a file that contains code to delete a file 

example :-

    $(window).unload( function () {

    $.ajax({
       url: "page_which_contains_file_deletion_code.jsp",
       success: function(data){
         alert("File Deleted Successfully");
       },
     async: false
     }); 
});

Upvotes: 1

Related Questions