简体   繁体   中英

Can we use printwriter with Apache poi worksheet

I am creating a workbook and trying to download the same. The issue I am facing I am when I use the workbook.write(outputstream), it seems both outputstream and printwriter will not work together and this is creating an response already committed exception for me. Could you please let me know whether we have any ways to write this using printwriter, so I will come out of response already committed exception.

pRes.setContentType(MS_EXCEL); pRes.setHeader(CONTENT,FILENAME);

        outputStream = pRes.getOutputStream();
        workbook.write(outputStream);

The exception i am getting is,

java.lang.IllegalStateException: getOutputStream() has already been called for this response at org.apache.catalina.connector.Response.getWriter(Response.java:619) at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198) at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125) at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118) at org.apache.jasper.runtime.JspWriterImpl.flush(JspWriterImpl.java:173)

由于您是从jsp调用的,因此需要将此<%@ page trimDirectiveWhitespaces="true" %>到页面中,以防止空格干扰您的输出流。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM