问题描述
我正在JSF和spring中创建一个项目,其主要目的是在浏览器中生成PDF文件.一切似乎都很好并且也生成了pdf,但在控制台上我遇到了这个异常.有人对此有想法吗?经过搜索,发现很多人都遇到了这个问题,但是我没有找到任何解决方案.
I am creating a project in JSF and spring whose main only purpose is to generate PDF file in the browser. Everything seems fine and pdf generated too but on console i am getting this exception.Anyone have idea about this? I have searched and found that many peoples had that problem but i didn't find any solution for mine one.
SEVERE: Error Rendering View[/WebPages/SearchPages/index.xhtml]
java.lang.IllegalStateException: PWC3991: getOutputStream() has already been called for this response
在创建输出流对象时出现此错误
I am getting this error while creating my outputstream object
HTTPServletResponse response = (HTTPServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
ServletOutputStream out = response.getOutputStream();
我的创作过程中是否有任何问题或其他原因?任何帮助都将不胜感激
Is there any problem while my creation or anyother reason? Any help would be greatly appreciable
推荐答案
您需要告诉JSF自己已经完成了HTTP响应,否则JSF在动作方法完成后仍将继续执行默认的RENDER_RESPONSE作业,完全会导致此异常,因为响应已经提交.
You need to tell JSF that you've already completed the HTTP response yourself, otherwise JSF will still continue doing the default RENDER_RESPONSE job after the action method is finished, which would result in exactly this exception, because the response is already committed.
您可以通过调用 FacesContext#responseComplete()
在操作方法中.
You can do that by calling FacesContext#responseComplete()
in the action method.
向JavaServer Faces实施信号,表明已经生成了针对此请求的HTTP响应(例如HTTP重定向),并且应在当前阶段完成后立即终止请求处理生命周期.
Signal the JavaServer Faces implementation that the HTTP response for this request has already been generated (such as an HTTP redirect), and that the request processing lifecycle should be terminated as soon as the current phase is completed.
另请参见:
- 如何提供从JSF支持bean下载文件?
- How to provide a file download from a JSF backing bean?
See also:
这篇关于错误呈现视图:java.lang.IllegalStateException:已为此响应调用getOutputStream()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!