getting error “getOutputStream() has already been called for this response”

时间秒杀一切 提交于 2019-12-24 14:57:13

问题


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.

Now my question is,

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;

Frameworks :

Spring-MVC,Hibernate

Exception :

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

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


回答1:


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.

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



来源:https://stackoverflow.com/questions/11271816/getting-error-getoutputstream-has-already-been-called-for-this-response

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