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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With