I found many of the answers in these forums very useful for me but would request you to check this issue of mine.
I'm trying to save a .csv
file from a servlet that is called by a jquery method. Though I'm setting the header and the content-diposition
. I'm not getting the dialogue box in the browser after stream writing the data.
function popup(data) {
$.post("cisco-fetch-devices", { orderId : data},
function(data) {
alert("Data Loaded: " + data);
});
});
}
The above jquery code is calling the below servlet post method:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/csv");
response.setHeader ("Content-Disposition", "attachment;filename=\"tableincsv.csv\"");
java.io.PrintWriter out = response.getWriter();
out.print("test data");
}
After the data is sent back to the browser, the dialogue box is not displayed. However the data that is set in the servlet out.print
is displayed correctly displayed in the alert
message of the JS method.
Please give me your inputs on this.
Thanks, aditya