Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel File Download Using JSP

Status
Not open for further replies.

AR1982

MIS
Jun 16, 2003
9
0
0
US
I have one program that makes excel reports from an Access database using POI. This program saves the reports to a Tomcat server on my system. I have a JSP called DisplayReports which uses a JavaBean to find the files on the server and post links for each file to another JSP called DownloadFile. When i link is clicked on DisplayReports.jsp, it is suppose to run Downloads.jsp, the Open/Save dialog box opens and then it down loads to the user specified directory. The relevant portion of the code in Download.jsp looks like this:

String filepath = dbBean.getDataPath();
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition",
"attachment; filename=\"" + filename + "\"");

POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filepath + filename));
HSSFWorkbook wb = new HSSFWorkbook(fs);
FileOutputStream fileOut = new FileOutputStream(filename);

wb.write(fileOut);
fileOut.close();


It downloads the excel workbook with the correct name but their is no data and no sheets. What do I need to add?
 
I figured the answer out. For anyone who wants to know, you just add the line:

wb.write(response.getOutputStream());

Insert it between wb.write(fileout); and fileout.close();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top