I have a Java Servlet for File Download (taken from the examples on this page (Implementing a simple file download servlet) that works in general but not when started via query.
The setup works as follows: When clicking on a button (input type submit) a file is generated and stored on the server. The response is redirected to the file download servlet which then streams the content of the generated file to the response. This works perfectly fine, except when starting the download procedure via a jQuery post function call.
When looking at the requests the only difference I could find was the accept-header of the request. This was / for the jQuery post and 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8' for the form submit request.
Could that be the decisive difference? And if so, how can I set what to accept?
This is the function call for the post in js:
$.post("path", {
action : "action",
ids: ids.toString()
}, null, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
This is the part where I set the content-disposition:
resp.addHeader("content-disposition:",
"attachment; filename=name.csv");