It's not a secret anymore!
The moose likes Servlets and the fly likes How to determine contentLength Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "How to determine contentLength" Watch "How to determine contentLength" New topic
Author

How to determine contentLength

Franco Finstad
Greenhorn

Joined: May 02, 2003
Posts: 22
I need to use the response.setContentLength() method in my servlet, but I'm not sure how to determine the content length of the actual data I will be sending. I'm working with a basic struts app.

Any ideas?
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
I am confused. Can't you just check the length?


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 13000
    
    5
If you write the data into a ByteArrayOutputStream first, you will be able to use the resulting size() and then write the buffer to the response output stream.

See the java.io package javadocs for details

Bill
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: How to determine contentLength
 
It's not a secret anymore!