getOutputStream()错误后无法调用getWriter()

时间:2012-07-14 03:00:06

标签: jsf-2 weblogic11g

我正在使用my-faces 2.1.5 primefaces 3.2和WebLogic Server Version:10.3.2.0

当我生成文件并尝试通过p:fileDownload下载时,我收到以下错误消息:

java.lang.IllegalStateException: strict servlet API: cannot call getWriter() after getOutputStream()
at weblogic.servlet.internal.ServletResponseImpl.getWriter(ServletResponseImpl.java:309)
at org.apache.myfaces.context.servlet.ServletExternalContextImpl.getResponseOutputWriter(ServletExternalContextImpl.java:185)
at org.apache.myfaces.renderkit.ErrorPageWriter.handle(ErrorPageWriter.java:469)
at org.apache.myfaces.context.MyFacesExceptionHandlerWrapperImpl.handle(MyFacesExceptionHandlerWrapperImpl.java:301)
at javax.faces.context.ExceptionHandlerWrapper.handle(ExceptionHandlerWrapper.java:64)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:191)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3592)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

我不知道这是weblogic中的错误还是我的代码中的错误?

此消息是我获得的唯一参考,我不知道如何解决此问题

jsf文件:

<p:commandButton id="genButton" value="Generate Files" disabled="#{bean.disableButton}" actionListener="#{bean.generate}" onclick="PrimeFaces.monitorDownload(showStatus, hideStatus)" ajax="false" style="width:200px" icon="ui-icon-shuffle">
        <p:fileDownload value="#{bean.zipfile}"/>  
        </p:commandButton> 

豆子:

     File zip = File.createTempFile(selectedCode, "zip");  

            ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip.getPath()));  
            for (File file : adapter.listFiles) {  
                addFileToZip(file, zos);  
            }  

            InputStream in = new FileInputStream(zip);  
            file = new DefaultStreamedContent(in, "zip", selectedCode + ".zip");  
            adapter.listFiles.clear();  
            zos.flush();  
            zos.close(); 

2 个答案:

答案 0 :(得分:2)

stacktrace告诉MyFaces异常处理程序试图处理它。

at org.apache.myfaces.context.MyFacesExceptionHandlerWrapperImpl.handle(MyFacesExceptionHandlerWrapperImpl.java:301)
at javax.faces.context.ExceptionHandlerWrapper.handle(ExceptionHandlerWrapper.java:64)

只有在抛出 异常时才会发生这种情况。但是异常的异常细节反过来显然被抑制了,因为MyFaces异常处理程序无法处理异常,因为无法获取响应编写器。

关闭MyFaces异常处理程序,您将获得真正的异常详细信息。

答案 1 :(得分:0)

看起来我找到了解决方案:)

如果列表为空,那么......

  else {
            if (streamedContent != null) {
                streamedContent.getStream().close();
                streamedContent = null;
            }
        }

感谢您的帮助。