I'm sorry, but I still don't get it. I understand the HTTP request overhead
issue. But let's say I have this code:

        StringBuffer buffer = new StringBuffer();

        buffer.append("<HTML>");
        buffer.append("<IMG SRC=\"/logo.gif\">");
        buffer.append("</HTML>");

        response.setContentLength(buffer.length());

How this is supposed to help? The browser makes only one request to get the
whole servlet output. Then it makes another to retrieve the image (I can't
avoid that). And even if I make a lot of requests to the same servlet, I
will only make one HTTP request each time. So I don't see the point in
setting the Content-Length..

And if the output of the servlet had more content, anyway the browser will
make only one HTTP request...

In my servlets I'm buffering all the output in StringBuffers, so it's pretty
easy for me to set the ContentLength, but I really don't get why I should do
it.


> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's
> Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On
> Behalf Of Craig
> R. McClanahan
> Sent: Wednesday, August 18, 1999 10:00 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Setting content-length
>
>
> "Andr�s Aguiar" wrote:
>
> > But the browser does only one http request for a simple
> servlet, doesn't it?
> > If I only have text in my servlet output (no <IMAGE>, etc),
> how can it help?
> >
>
> If you only make one request to one servlet in your entire
> life, then no it
> won't help.
>
> If you make additional requests to the same servlet, or to
> different servlets
> (or HTML pages, or images, or whatever) on the same server,
> then the fact that
> you are not creating a TCP connection every time can help a lot.
>
> As you are surfing around the web some time, pay attention to
> the status line
> when you click on a link.  You know how it goes from
> "contacting host xxx" to
> "host contacted, waiting for reply"?  A pretty good chunk of
> the time between
> these messages is setting up a TCP connection for your
> request, and that's
> where the time savings comes from -- not on the very first
> request, but on
> every request after that.
>
> Craig McClanahan
>
> ______________________________________________________________
> _____________
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources:
http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to