I am currently working with jQuery and Spring Rest. jQuery is used to upload and download files to the Server. The upload process is working fine but I have little problem with downloading the files. So the scenario is, in the view, the user will select the n numbers of files to download and clicks the download button. Once the user clicks that button, the files will be downloaded. I do not want to open a new new tab for each file download. I would like to download on the same window without refreshing the current view. I looked into this but didn't help me much. Is there any way, I can achieve this?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- Carriage Return (ASCII chr 13) is missing from tex
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
I answered something similar a few minutes ago: sending file from response to user, Spring REST + jQuery
I recommend you to use this JS plugin https://github.com/johnculviner/jquery.fileDownload to download the file instead using $.ajax directly. You can find all the official documentation there.
Also, in your controller, you have to take your HttpServletResponse and write the byte[] in the outputstream, and you have to put a cookie in the response to advise the JS plugin (because it needs it)
For example:
Here is my solution to download the file:
Spring Controller method:
}
On client side function: