Getting error "getOutputStream () has already been called for this response"

I am showing a report of some event. I need the controller to show a popup to save and open.

I have already set the file in the answer, after setting the answer, I return the view.

Now my question is:

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

In my class class, I wrote the 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;

      

Framework:

Spring-MVC, hibernate

An exception:

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

Desired O / P: I want the response to display a popup for the file and would like the browser to redirect to a different view.

+1


source to share


1 answer


During request processing is called as HttpServletResponse.getWriter()

, and HttpServletResponse.getOutputStream()

. And according to the spec, it is illegal to use both OutputStream and Writer.



The exception you are getting is thrown when you try to invoje HttpServletResponse.getWriter()

somewhere else /

+1


source







All Articles