问题描述
你好我有一个问题,我不能把我的手指..... .....
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 )
在上面的代码中,假设outStream有一个读入pdf文件。第一次请求代码呈现良好。在第二次请求时,我得到:
pre $ java.lang.IllegalStateException:getOutputStream()已经被调用了这个响应
输出流是什么并不重要。即使我制作了一个全新的字节[2],并且写出了相同的结果。在第一次请求服务器响应良好。第二,上面的例外发生....
任何帮助将是受欢迎的
getOutputStream()
,或者做任何会导致它被调用的东西。所以我得出结论,异常的原因是在别的地方。 底线是您只能调用 ServletResponse.getOutputStream()
和/或 getWriter()
给定响应一次。某处,您的应用程序多次调用 getOutputStream
或 getWriter
。
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.
这篇关于getOutputStream()已经在第二个servlet请求上为此响应调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!