3

I have a download icon in jsp page, when i click on download icon, spring controller is called and ther i need to handle the code to download the file and save in your local machine same as downloading attachments from mail. I tried by setting "response.setHeader("Content-Disposition", "attachment;filename="abc.txt")" but could not see any option to save the file. Thanks

0

1 Answer 1

0

You simply cannot download a file from an HTTP server through AJAX. Instead, once you are ready, change your window location to the download link

window.location = contextPath + "/download.htm"; // with whatever request parameter

The browser will make a GET request to that location. If the response is a file download (with content-disposition) you'll get prompted for the target directory and your browser page won't change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.