• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Content Length not being sent to client in HTTP headers

 
wayne forrest
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic