hello i have a problem that I cannot put my finger on.....
servletResp.setHeader("Expires","0")
servletResp.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0")
servletResp.setHeader("Pragma","public")
servletResp.setHeader("Content-Disposition","inline; filename=invoice.pdf")
servletResp.setContentType("application/pdf")
servletResp.setContentLength( outStream.size())
servletResponseStream.write(outStream.toByteArray())
outStream.close()
servletResponseStream.flush()
servletResponseStream.close()
In the above code assume that outStream has a read in pdf file. The code renders fine on first request. On second request I get:
java.lang.IllegalStateException: getOutputStream() has already been called for this response
it doesn't matter what outputstream is. Even if I make a brand new byte[2] and write that the same result happens. On first request the server responds fine. On second the above exception happens....
Any help would be welcome
The code in your question doesn't call getOutputStream()
, or do anything that would cause it to be called. So I'd conclude that the cause of the exception is somewhere else.
The bottom line is that you can only call ServletResponse.getOutputStream()
and/or getWriter()
once for a given response. Somewhere, your application is calling getOutputStream
or getWriter
more than once.
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.