Monday, December 11, 2017

ERROR: java.lang.IllegalStateException: getOutputStream() has already been called for this response

最近遇到一個問題超難搞的,就是這個︰
SEVERE: Servlet.service() for servlet [jsp] in context with path ... threw exception [java.lang.IllegalStateException: getOutputStream() has already been called for this response] with root cause
at org.apache.catalina.connector.Response.getWriter(Response.java:678)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:213)
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.PageContextImpl.release(PageContextImpl.java:194)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:126)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:80)

就是用JSP直接打開一個系統存在的PDF文件這麼簡單,但卻弄了很久也沒解決。
打開PDF的方法可參考這個︰Displaying pdf in jsp

其實JSP是打開了PDF文件,但同時JSF請求了getWriter,而getOutputStream被JSP用了,所以JSF無法使用getWriter而報錯。

暫時方法找不到,先不管了。

No comments: