java.lang.IllegalStateException: getWriter() has already been called for this response问题解决

java.lang.IllegalStateException: getWriter() has already been called for this response问题解决

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

在执行下述代码时报错,

OutputStream out = getResponse().getOutputStream();

 

原因为代码中有打开的Response.getWriter(),未关闭,因调用点较多,不好一一排查。

通过查看代码,看到response中的usingWriter=true,随即想办法将该标志位设置为false。

response.reset(); 即可,注意reset后缓存消失,设置消失。

 

OutputStream和Writer在一个response中不能同时获得。

你可能感兴趣的:(java.lang.IllegalStateException: getWriter() has already been called for this response问题解决)