Java Poi does not download

0

I'm using the poi 3.15 library to generate excel on a web system, but I'm having a hard time downloading the file locally, but when I do it does nothing. I put it in the beginning like this:

String  caminho   = System.getProperty("user.home");
String  filename  = caminho + "/arquivo.xls";

At the end:

try (FileOutputStream fileOut = new FileOutputStream(filename)) {
    workbook.write(fileOut);
}

and in the servlet I call:

case "EXPORTAR":
    new ClasseDAO().exportarExcel(id);
    dispatcher = request.getRequestDispatcher("pagina.jsp");
    dispatcher.forward(request, response);
break;

The call is in the action of a form, I tried setting ContentType with vnd.ms-excel, Header with attachment but it does not work.

    
asked by anonymous 14.02.2017 / 22:11

1 answer

1

You can write directly to the response request. Ex .:

response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachment; filename=qrquivo.xls");

wb.write(response.getOutputStream());
response.getOutputStream().flush();
    
28.08.2017 / 16:41