日期:2014-05-17  浏览次数:20635 次

poi 不弹出保存对话框
想要生成一个Excel 然后能够下载 并删除服务器端的文件 不知道哪写的不对 没反应啊

public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.reset();  
  response.setContentType("application/vnd.ms-excel;charset=utf-8");  
  response.setHeader("Content-Disposition", "attachment;filename="  
  + new String("系统日志.xls".getBytes(), "iso-8859-1"));


  ServletOutputStream out = response.getOutputStream(); 
BufferedInputStream bis = null;  
BufferedOutputStream bos = null;  
 
try {  
//excel.getInputStream(str, list) 得到输入流
bis = new BufferedInputStream(excel.getInputStream(str, list));  
bos = new BufferedOutputStream(out);  
 
byte[] buff = new byte[2048];  
int bytesRead = 0;  
 
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {  
bos.write(buff, 0, bytesRead); System.out.println("read");
}  
bos.flush();
} catch (final IOException e) {  
System.out.println("IOException.");  
throw e;  
} finally {  
if (bis != null)  
bis.close();  
if (bos != null)  
bos.close();  
}

------解决方案--------------------
记得好像应该用response写出去啊,response.writeXX(你的数据);
具体记不太清了,你再找找吧!