• 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: 13064
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic