I just encountered the same problem in my recent work.
We have a servlet filter in which we use ServletResponse.getWriter() method to write the body, and in some Spring MVC controller, we also use response.getOutputStream() to write something like images(array of bytes) into body.
Since every request will go through filter, and based on Java API doc:
"Either this method(getWriter()) or getOutputStream() may be called to write the body, not both."
That's the reason why we got the "java.lang.IllegalStateException: getOutputStream() has already been called for this response" exception.
So in that filter, I changed the code to:
ServletOutputStream sos = response.getOutputStream();
sos.write(newHtml.getBytes("UTF8")); // newHtml is a String.
sos.flush();
It fixed this issue for me.