I'm trying to use Servlet to download data as CSV, and as the JSP is included with flush=true
. The stack trace is provided below. The report is getting saved as expected but I can see an exception in the back. Can you please help me figure out why? I have closed the OutputStream
and also tried flushing the buffer, but still no luck.
1:36:38,304 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
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)
at atg.taglib.dspjsp.IncludeTag.flushOut(IncludeTag.java:873)
at atg.taglib.dspjsp.IncludeTag.doEndTag(IncludeTag.java:773)
pResponse.setContentType(MS_EXCEL);
pResponse.setHeader(CONTENT,FILENAME);
outputStream = pResponse.getOutputStream();
pResponse.flushBuffer();
workbook.write(outputStream);
outputStream.flush();
outputStream.close();