aspose file tools*
The moose likes Servlets and the fly likes need some clarification about keep-alives and content-lengths Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "need some clarification about keep-alives and content-lengths" Watch "need some clarification about keep-alives and content-lengths" New topic
Author

need some clarification about keep-alives and content-lengths

Charles Cayman
Greenhorn

Joined: Jul 02, 2002
Posts: 8
ok, here the concept that gets me puzzled.
1.) I read that Keep-Alives are there to avoid unnecessary re-establishments of connections on web pages that have more than one file (e.g., with graphics, etc.)
2.) In a socket connection, the browser will know that a particular file is ended by counting the Content-Length header sent by the server, so that the browser can request more files.
3.) So, my impression is that, when we produce a file using
PrintWriter out = HttpServletResponse.getWriter();
out.println();...
The servlet postpones the sending of the text through the connection until it knows exactly how long the response is.
4.) So, now my question is: What happens if the HTML file that we're producing is larger than the output/response buffer (usually 8K)? The servlet must send the initial 8K of data, but it still does not know how many will be sent...
If it does not know the total length, then it can't set the Content-Length header...
but if it does not set the Content-Length header, then it can't send the data...

Where am I wrong here??? Thank you in advance
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12785
    
    5
Content-length is really only essential for resources like zip files, image files and pdf files where special handling is needed and you can figure out the length before sending anything. Browsers obviously can cope with HTML that just keeps on coming. A browser can start requesting images, etc. before the HTML is complete without opening a new connection.
Bill
Charles Cayman
Greenhorn

Joined: Jul 02, 2002
Posts: 8
Thanks for clearing that one up!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need some clarification about keep-alives and content-lengths