File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 12671
    
    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

Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Content Length not being sent to client in HTTP headers
 
Similar Threads
URL string replacing
Chunked transfer-encoding problem
Downloading Images from server
sendRedirect method
socket communication with AS400...