user3684675
user3684675

Reputation: 381

download the file as attachment

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

Upvotes: 3

Views: 375

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279940

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.

Upvotes: 0

Related Questions