You cannot return 2 responses to a single request. You can return only 1 response to 1 request. Uploading a file counts as one answer, and redirecting counts as another answer.
It is best to return a response that somehow automatically initiates a new request. Then a second response can be returned to this automatically triggered request. JavaScript is very useful in this with functions such as window.location (to start a new request in the current window), window.open() (to start a new request in a new window) and form.submit() (to send a POST form).
The easiest way is to redirect to the landing page, where some JavaScript is conditionally visualized (and immediately executed), which, in turn, starts downloading the file, for example. window.location or form.submit() . window.open() not suitable if the download itself is already installed as an attachment. Please note that this approach is not redirected after the user has saved the file download, it is simply not possible, since there is no case on the client side to connect when the last bit of the download is saved. Instead, a redirect is performed first, and then a file is downloaded.
If you really have a heavy head, you can always create an applet or web start application that completely controls the saving of the downloaded file so that you can easily redirect after saving the last bit. However, this IMO is just awkward (and even potentially bad for UX, for example, I personally hate such “download managers” on multiple sites).
source share