Error Rendering View: java.lang.IllegalStateException: getOutputStream() has already been called for this response

元气小坏坏 提交于 2021-02-17 05:02:34

问题


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


回答1:


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.

You can do that by calling FacesContext#responseComplete() in the action method.

responseComplete

public abstract void responseComplete()

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.

See also:

  • How to provide a file download from a JSF backing bean?


来源:https://stackoverflow.com/questions/12489543/error-rendering-view-java-lang-illegalstateexception-getoutputstream-has-alr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!