Report java.net. protocolexception: didn't meet stated Content-Length, wrote: '100

Source: Internet
Author: User

A large number of errors are reported in the background when you view Weblogic server logs today, as shown below:

Java.net. protocolexception: didn't meet stated Content-Length, wrote: '000000' bytes instead of stated: '000000' bytes.
At weblogic. servlet. Internal. servletoutputstreamimpl. ensurecontentlength (servletoutputstreamimpl. Java: 470)
At weblogic. servlet. Internal. servletresponseimpl. ensurecontentlength (servletresponseimpl. Java: 1176)
At weblogic. servlet. Internal. servletresponseimpl. Send (servletresponseimpl. Java: 1188)
At weblogic.servlet.internal.servletrequestimpl.exe cute (servletrequestimpl. Java: 2590)
At weblogic.kernel.executethread.exe cute (executethread. Java: 197)
At weblogic. kernel. executethread. Run (executethread. Java: 170)

After multiple tests, find a solution, mainly because when the image is downloaded,

Bis = new bufferedinputstream (Rs. getbinarystream (IMG ));

Response. setcontentlength (Rs. getint (2 ));
Response. setbuffersize (1024 );
Response. setcontenttype ("application/X-msdownload ");
Response. setheader ("content-disposition", "filename =" + infovariable. converu2a ("IMG "));
Servletoutputstream op = response. getoutputstream ();

Byte [] B = new byte [1024];
Int size = 0;
While (size = bis. Read (B ))! =-1)
Op. Write (B, 0, size );

The number of bytes imported to response is not set. You can add the following settings to solve this problem,

// Where Rs. getint (2) is the size of the Blob field in the database, which can be obtained through the dbms_lob.getlength (IMG) Function

Response. setcontentlength (Rs. getint (2); // note that the cotentlength is the image size.

If the image cannot be opened or is garbled, use response. resetbuffer (); refresh the cache.

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.