• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to determine contentLength

 
Franco Finstad
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confused. Can't you just check the length?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!