Exception:
Java. Lang. illegalstateexception: getoutputstream () has already been called for this response
Solution:
Call the following two lines after the output stream is used:CodeYou can: Out. Clear (); out = pagecontext. pushbody ();
That is:
ImageIO. Write (image, "Jpeg", response. getoutputstream ());
Out. Clear ();
Out = pagecontext. pushbody ();
Cause:
the servlet code generated by the Web container contains out. write (""), which corresponds to the response called in JSP. getoutputstream () produces a conflict. that is, the servlet specification description cannot call either response. getoutputstream () and call response. getwriter (), no matter which one is called first, the illegalstateexception should be thrown during the second call, because in JSP, The out variable actually uses response. according to getwriter, response is used in your Program . the above error occurs because the out variable is used again in getoutputstream.