aspose file tools*
The moose likes Servlets and the fly likes Content Length not being sent to client in HTTP headers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Content Length not being sent to client in HTTP headers " Watch "Content Length not being sent to client in HTTP headers " New topic
Author

Content Length not being sent to client in HTTP headers

wayne forrest
Greenhorn

Joined: Aug 23, 2010
Posts: 17
Hello,

I am having some trouble with the servlet API (Tomcat 6).

Setting the content length using the out.setContentLength(len) is not working, the headers is not sent
to the client when I monitor the traffic via WireShark, and yet out.println("Content-Length: "+len) works.

Is there an explanation for this?


William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
Most likely explanation is that your application has already flushed the headers to the response stream. You need to set all headers before the first write to the response stream just to be safe.

See the javax.servlet.ServletResponse JavaDocs where it is explained that setContentLength has no effect if the headers have already been sent and does not report any error.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Content Length not being sent to client in HTTP headers