permaculture playing cards
The moose likes Servlets and the fly likes HttpServletResponse content size? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpServletResponse content size?" Watch "HttpServletResponse content size?" New topic

HttpServletResponse content size?

Ralf Rottmann

Joined: Dec 07, 2003
Posts: 25
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.

-----------------------------<br /><a href="" target="_blank" rel="nofollow"></a><p>"The real voyage of discovery consists not in making new landscapes but in having new eyes." <br />Marcel Proust (1871-1922)
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13018
You could create a StringWriter as a local buffer and write everything to it , get the size, then output the resulting String.
Ralf Rottmann

Joined: Dec 07, 2003
Posts: 25
How do I output the StringWriter via the response-Object?
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8927

Check the example under Programming Customized Requests and Responses

I agree. Here's the link:
subject: HttpServletResponse content size?
It's not a secret anymore!