Java Servlet - setContentLength()

来源:互联网 发布:c 编程思想 pdf 编辑:程序博客网 时间:2024/05/01 14:02
Posts:27
Registered: 23/5/06 setContentLength()
Sep 29, 2006 2:59 AM
        I want to know what does setContentLength() method does.
My concern is that if a set content length to some value and then send less data to the stream , and afterwards when i read back from httpResponse object , will there be any issues ...like null characters, or junk characters etc.
        More over if we write to stream without setting content length will it work?
        Plz help
        brian@cubik.ca
Posts:458
Registered: 1/18/04 Re: setContentLength()
Sep 29, 2006 3:16 PM (reply 1 of 1)
        It causes the Content-Length header to be set with the value you provide it. You don't really need it for sending back type 'text/html', but if you're sending binary files, it's the only way that the progress indicator in your browser will work. Sending the wrong Content-Length header will probably result in browser-dependant weirdness. Perhaps the file will be truncated. The progress indicator may hit 100% and still be downloading. If you don't know how long the Content is, then don't send the header.

Brian