获得错误“getOutputStream()已被调用此响应” [英] getting error "getOutputStream() has already been called for this response"

查看:1625
本文介绍了获得错误“getOutputStream()已被调用此响应”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在显示一些事件的报告。我希望控制器显示弹出窗口以进行保存并打开。

I am showing report on some event.I want controller to show popup for save and open .

我已经设置文件作为响应,设置响应后我返回查看。

I already set file in response , after setting response i am returning view.

现在我的问题是,

我收到错误java.lang.IllegalStateException:getOutputStream( )已经被调用了这个响应

I am getting error " java.lang.IllegalStateException: getOutputStream() has already been called for this response"

在我的控制器类中,我写了以下代码:

In my controller class i have written following code :

......一些代码.......

......some Code.......

InputStream is =
        new FileInputStream(new File("c:/reports/test_jasper.pdf"));
            response.setHeader("Content-Disposition","attachment;filename=\"test_jasper.pdf\"");
            OutputStream opStream = response.getOutputStream();
            IOUtils.copy(is, opStream);
            response.flushBuffer();
            HttpServletResponse response1 = new HttpServletResponse();



        model.addAttribute(ABC, new abc());

        model.addAttribute(DEF, new def());
        return SOME_VIEW;

框架:

Spring-MVC,Hibernate

Spring-MVC,Hibernate

异常:

java.lang .IllegalStateException:getOutputStream()已被调用此响应

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

所需的O / P:
我想要回应来显示弹出窗口对于文件,并希望浏览器重定向到其他视图。

Desired O/P : I want response to show popup for file , and want browser to redirect to some other view.

推荐答案

在请求处理期间, HttpServletResponse正在调用.getWriter() HttpServletResponse.getOutputStream()。根据规范,使用OutputStream和Writer是非法的。

During the request processing both HttpServletResponse.getWriter() and HttpServletResponse.getOutputStream() are being called. And as per the spec, it is illegal to use both OutputStream and Writer.

尝试invoje HttpServletResponse时抛出异常.getWriter()其他地方/

The exception you are getting is being thrown while trying to invoje HttpServletResponse.getWriter() somewhere else/

这篇关于获得错误“getOutputStream()已被调用此响应”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆