I have a webapplication that runs on websphere on a server from the office. The main page shows a table with data. When I choose export from the menu, it has to export the data to an excel sheet. I use apache poi for this. When I made my workbook, I write it via FileOutputStream. And here, I don't know exactly what I have to do. When I choose new File("C:\Temp\test.xls"), it will write the file on the server site. But I want that the application will export the file to excel on the client side folder. How can I do this?
Thx
Update: I searched a lot on this problem and they all answer the same, so I tried their solution:
HttpServletResponse res = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
res.setContentType("application/vnd.ms-excel");
res.setHeader("Content-disposition", "attachment; filename=test.xls");
try {
ServletOutputStream fileOut = res.getOutputStream();
workbook.write(fileOut);
fileOut.flush();
fileOut.close();
}
catch (FileNotFoundException e) {
System.out.println("... FileNotFoundException ...");
e.printStackTrace();
}
catch (IOException e) {
System.out.println("... IOException ...");
e.printStackTrace();
}
System.out.println("... excel file created ...");
FacesContext faces = FacesContext.getCurrentInstance();
faces.responseComplete();
But still i do not get a popup screen where i can choose the direction on the client. So this solution doesn't work.