Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirection or Refresh Page After Zip Download

I am calling the servlet through href in my .vm file(as I am using velocity framwork for front end) when the request goes to servlet I am downloading a file on that. The file genration for downloading in takes around 30 seconds so I want to indicate end user through pop-up, For this I have called a function on same href in my .vm file which is opening a pop up indicating that file is generating currently so please wait. but when file generation and downloading finish I want to remove that pop up. I was tried this through redirection on servlet but after googled I found that we can't change the status of response after downloading (link).

I am calling javascript function and servlet in my vm file like this

 <a href="/overriderulehandler?report=1" onClick="return reportResponse()"> Generate Report </a>

overriderulehandler is calling my servlet and I am preparing file for download here and reportResponse is JS function in which I am opening popup.

Please suggest me how should I do this task. If anyone have other idea about this please share. Any help is appreciated.

like image 688
kailash gaur Avatar asked Jul 16 '14 09:07

kailash gaur


1 Answers

This onClick handler works for me.

onclick="setTimeout(function(){window.location.href='test.html'},100)"

You can put it in your anchor tag that calls your servlet and the encapsulated anonymous function can call any other function you like. 'test.html' could be a page that says "Your file is being prepared and will download shortly.

The content type of the response on the servlet should match the file type you are pushing so that the browser knows to download the file rather than try to open it.

like image 75
J E Carter II Avatar answered Nov 09 '22 07:11

J E Carter II