java.lang.IllegalStateException:已为此响应调用了getOutputStream()

当我尝试从客户端请求从服务器加载图像时,我收到以下异常:

241132533 [TP-Processor1] ERROR [/jspapps].[jsp] – Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response

任何人都可以向我解释这个例外以及如何克服它吗?

can any one explain this exception to me

您正在尝试使用JSP文件中的原始Java代码将二进制数据写入response.getOutputStream(),该文件本身已使用response.getWriter()来编写任何模板文本.另请参见链接的javadocs的Throws部分.

and also how to get over it?

而是在真正的Java类中编写Java代码.创建一个扩展HttpServlet的类,将所有Java代码移动到那里,将其映射到web.xml并更改请求URL以调用servlet.

也可以看看:

> Beginning and intermediate JSP/Servlet tutorials
> Basic example of an image servlet
> How to avoid Java code in JSP files

翻译自:https://stackoverflow.com/questions/3540464/java-lang-illegalstateexception-getoutputstream-has-already-been-called-for-t

转载注明原文:java.lang.IllegalStateException:已为此响应调用了getOutputStream()