Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpServletResponse content size?

 
Ralf Rottmann
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I have a servlet which sends a lot of text to the response PrintWriter based on a db lookup. At the end of each paged served by this servlet I want to output an info about the size of the page the web visitor just has retrieved, e.g.:
"This page is 36.340 bytes in size."
Any idea how to do this? There seems to be no getContentSize method available in HttpServletResponse.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could create a StringWriter as a local buffer and write everything to it , get the size, then output the resulting String.
Bill
 
Ralf Rottmann
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I output the StringWriter via the response-Object?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the example under Programming Customized Requests and Responses
http://java.sun.com/products/servlet/Filters.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic