Redirecting or refreshing a page after downloading a ZIP

I call the servlet via href in my .vm file (since I use the framework speed for the front end) when the request is sent to the servlet. I am uploading a file. Generating files to download takes about 30 seconds, so I want to specify the end user through a popup window. To do this, I called a function on the same href in my .vm file, which opens a pop-up window indicating that the file is currently being generated so Please wait. but when you create and upload files, I want to remove this popup. I tried this through redirecting to the servlet, but after googled I found that we cannot change the status of the response after loading ( link ).

I call javascript function and servlet in my vm file as

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

the overriderulehandler calls my servlet, and I prepare the file for upload here, and reportResponse is a JS function in which I open a popup.

Please suggest me how I should complete this task. If anyone has any other ideas, please share. Any help is appreciated.

+8
java javascript servlets
source share
2 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 that you like. "test.html" could be a page that says: "Your file is being prepared and will be downloaded soon.

The content type of the response to the servlet should match the type of file that you click so that the browser knows to download the file, and not try to open it.

+1
source share

The method I found for redirection after loading is to use two different html / javascript / JQuery event handlers. The redirection handler is loading Onmousedown. Thus, on the mouse down js will generate a PDF file and load, and then a redirection will be performed on the mouse up. Thank God that this works ... it's pretty simple to implement too.

 <a href="#" target="_blank" onmousedown="javascript:createPDF(<?php echo $ID; ?>,'actionName','pageName'); return false;">Create PDF</a> 

Blessings!

0
source share

All Articles