简体   繁体   中英

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

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM