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

How to determine contentLength

Franco Finstad

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?

So much trouble in the world -- Bob Marley
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12839
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 package javadocs for details

I agree. Here's the link:
subject: How to determine contentLength