下载POI文件无法打开jsp

问题描述

im试图在jsp中下载POI文件。但是它无法通过说“您正在尝试打开其他文件格式....”来打开。我不知道我在哪里缺少.. 预先感谢。

  <%
  try{
       hssfWorkbook wb = new hssfWorkbook();
       hssfSheet sheet = wb.createSheet("Excel Sheet");
       hssfRow rowhead = sheet.createRow((short) 0);

       rowhead.createCell((short) 0).setCellValue("lOGINID");
       rowhead.createCell((short) 1).setCellValue("CUSTOMERID");
       rowhead.createCell((short) 2).setCellValue("REQUEST_DATE");
       
       int index = 1;
       for (int i = 0; i < list.size(); i++) {
         EdisCustomers data = new EdisCustomers();
         data = list.get(i);
         hssfRow row = sheet.createRow((short) index);

         row.createCell(0).setCellValue(data.getLoginid());
         row.createCell(1).setCellValue(data.getCustomerid());
         row.createCell(2).setCellValue(data.getRequestdate());
        index++;
    
     }

    ByteArrayOutputStream outByteStream = new ByteArrayOutputStream(); 
    wb.write(outByteStream);
    byte [] outArray = outByteStream.toByteArray();
    response.setContentType("application/ms-excel");
    response.setContentLength(outArray.length); 
    response.setHeader("Expires:","0"); // eliminates browser caching
    response.setHeader("Content-disposition","attachment; filename=EdisAudiReport.xls");
    OutputStream outStream = response.getoutputStream();
    outStream.write(outArray);
    outStream.flush();
    outStream.close();

    out.clear(); // where out is a JspWriter
    out = pageContext.pushBody();

    response.getoutputStream().flush();
    response.getoutputStream().close();


  }catch(Exception e){

}finally {

response.getoutputStream().flush();
response.getoutputStream().close();
out.clear();
}

%>

我还需要做点其他事情。从其他教程中,我找到了此代码。但无法下载。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)