getOutputStream() has already been called for this response
用jsp实现文件下载、图片验证码等功能时,有时会产生getOutputStream() has already been called for this response异常信息。
原因是在将jsp代码编译成servlet后,程序中会调用response.getWriter(),而这段代码和你编写的response.getOutputStream()相冲突,程序认为他们的作用是一样的,没必要调用两次,所以在运行时,程序报getOutputStream() has already been called for this response。
解决办法:
使用完输出流以后添加以下两行代码:
[java] view plaincopyprint?
01.out.clear();
02.out = pageContext.pushBody();