`

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

 
阅读更多

异常描述:

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

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

 

产生原因:

如果一次请求响应过程中已经获取PrintWriter out = response.getWriter();过,再次通过response.getWriter();或

response.getOutputStream();获取输出流时将产生该异常。

 

解决方法:

最直接有效的方法就是在一次请求响应中只在一个地方获取该输出流。

 

其他解决办法,参考网上的讨论:

JSP默认的输出流为PrintWriter ,即<% %>以外的东西,即默认的输出方式,如果你尝试在JSP中使用

ServletOutputStream就会引起错误.要么直接改用Servlet输出 (复写service方法),要嘛删除除%><%中的任何东

西(包括HTML标签,空格,回车等东西)应该就可以。
对于这样的情况应该这样来解决,删除%><%之间的所有内容包括空格和换行符,最后也要消除空格和换行符,

最好再加上一句response.reset()。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics