Verification Code exception: Java. Lang. illegalstateexception: getoutputstream () has already been called for this response

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.