"Andr�s Aguiar" wrote:
> 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.
>
No, you don't appear to understand the HTTP request stuff yet.
Your image is on the same server as the servlet, right? Therefore, your
browser is going to make a second request to your server -- even though it
isn't going to your servlet, or any servlet, to get the image.
The request for the image will benefit from the performance improvement under
the following circumstances:
* Your server supports HTTP/1.1
* Your browser supports HTTP/1.1
* You set the content length in the servlet output.
If you don't set the content length, you still MIGHT benefit because the server
might be able to set the content length for you (on a servlet output this
short, that's pretty likely) -- but there's no guarantee.
To reiterate again ( :-) ), setting the content length has no impact on the
HTTP/1.1 benefit for the request you are currently responding to -- but it
enables the use of HTTP/1.1 on subsequent requests from the same browser to the
same server. If that's not clear enough, then, it's someone else's turn to try
to explain it, or you need to just take it on faith that it's a good idea.
Craig
___________________________________________________________________________
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