getWriter() has already been called for this response

PrintWriter out = response.getWriter();
response.setHeader("contentType", "text/html; charset=utf-8");
response.setContentType("text/html;charset=utf-8");
out.write("test");
out.close();;
return resultModel;

什么这段controller中的代码调用,会抛出下面的异常:

getWriter() has already been called for this response

at org.apache.catalina.connector.Response.getOutputStream(Response.java:530)

at org.apache.catalina.connector.ResponseFacade.getOutputStream(ResponseFacade.java:195)

at org.springframework.http.server.ServletServerHttpResponse.getBody(ServletServerHttpResponse.java:89)

后来将controller中返回参数 直接修改为void,  或者返回的时候 返回null 就好了

PrintWriter out = response.getWriter();
response.setHeader("contentType", "text/html; charset=utf-8");
response.setContentType("text/html;charset=utf-8");
out.write(day + "的回盘文件还没有生成");
out.flush();
out.close();
return;

 

发表评论

邮箱地址不会被公开。