Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法在weblogic 11+;中成功导出excel;linux_Java_Excel_Jasper Reports_Ireport_Export To Excel - Fatal编程技术网

Java 无法在weblogic 11+;中成功导出excel;linux

Java 无法在weblogic 11+;中成功导出excel;linux,java,excel,jasper-reports,ireport,export-to-excel,Java,Excel,Jasper Reports,Ireport,Export To Excel,我们使用上面的代码生成excel,它在tomcat+windows中运行良好,但在我们上传到linux+weblogic服务器后,excel已损坏。我用文本编辑器打开excel,我发现它在excel中添加了几行空行,这导致excel无法成功打开,有人能给我指出正确的方向吗?为什么会有空间?它是怎么来的 提前谢谢 我怀疑您使用pageContext.pushBody()可能是罪魁祸首。 据我所知,pushBody用于更新JSP标记范围内的输出 当您生成二进制内容(如excel文件)时,需要绝对确保

我们使用上面的代码生成excel,它在tomcat+windows中运行良好,但在我们上传到linux+weblogic服务器后,excel已损坏。我用文本编辑器打开excel,我发现它在excel中添加了几行空行,这导致excel无法成功打开,有人能给我指出正确的方向吗?为什么会有空间?它是怎么来的


提前谢谢

我怀疑您使用pageContext.pushBody()可能是罪魁祸首。 据我所知,pushBody用于更新JSP标记范围内的输出

当您生成二进制内容(如excel文件)时,需要绝对确保预期的字节(并且只有预期的字节)到达浏览器,您需要写入这些字节,刷新输出,然后确保没有写入任何其他内容。通过调用pushBody(),可以将更多内容写入输出,并且可以输出JSP页面中的任何空行(以及它们之间的回车/换行符)


总之,我建议您不要在JSP中执行此操作,而是在Servlet中执行。

您可以共享由Linux系统和Windows系统生成的简单.xls吗?区别在于Linux系统中有几行空格,删除这些空格后,它可以成功打开,或者它是一个xml文件,对吗?不,我用一个文本编辑器打开它,删除这些空格后,我用excel打开它。
<%
         response.reset();
         response.setHeader("Content-Disposition", "attachment;filename=\"" + "test.xls\"");
         response.setHeader("Content-Transfer-Encoding", "binary");
         response.setContentType("application/vnd.ms-excel");

        InputStream is = new FileInputStream(realPath);
        //OutputStream outStream = response.getOutputStream();

        JasperPrint jasperPrint = JasperFillManager.fillReport(is,
                parameters, new JRBeanCollectionDataSource(pdfList));

        JRAbstractExporter exporter = new JExcelApiExporter();
         exporter.setParameter(JExcelApiExporterParameter.JASPER_PRINT, jasperPrint); 
         exporter.setParameter(JExcelApiExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE); 
         exporter.setParameter(JExcelApiExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
         exporter.setParameter(JExcelApiExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
         exporter.setParameter(JExcelApiExporterParameter.OUTPUT_STREAM, out);
         exporter.exportReport();

         outStream.flush();
         outStream.close();

         out.clear();
         out =pageContext.pushBody();
    %>