Java Servlet:无法创buildExcel文件

我很难得到一个Servlet Excel file using apache POI创build一个Excel file using apache POI

当我在单独的Java类中使用下面的代码时,它工作正常,但是当我将代码复制到servlet中时,servlet不会创buildexcel文件。

这基本上就是servlet中的全部内容。 我得到的参数,只是存储这些。 我只想让servlet先创build文件,然后再开始添加用户input。

 Workbook workbook = new HSSFWorkbook(); Sheet sheet = workbook.createSheet("Sheet 1"); Cell cell1 = sheet.createRow(0).createCell(3); cell1.setCellValue("100000"); Cell cell2 = sheet.createRow(1).createCell(3); cell2.setCellValue("Text text."); FileOutputStream output = new FileOutputStream("SampSamp.xls"); workbook.write(output); output.close(); 

我试过你的代码,并在c:\glassfish3\glassfish\domains\domain1\config文件夹中创build文件。 也许你考虑给绝对path。 例如:C:\ temp \ SamSamp.xls。