I'm doing a java application where you have to download a CSV file. But it is happening to me that the browser does not show the download dialog, but shows it embedded in the browser itself.
This is the code of my servlet:
List<MisDatosBean> listaDatos = miDAL.obtenerDatos();
if (listaDatos!= null) {
PrintWriter writer;
writer = response.getWriter();
for (MisDatosBean d : listaDatos) {
CSVUtils.writeLine(writer, generarLista(d));
}
response.setContentType("text/csv");
response.setHeader("Content-Disposition", "attachment; filename=\"datos.csv\"");
if (!request.isSecure()) {
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setHeader("Expires", "0");
}
writer.flush();
writer.close();
}
What else should I indicate, so that it shows me the download dialog? It happens to me in all the browsers I've tried, both IE11, firefox and chrome.