Meaningless Drivel is fun!*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpServletResponse content size?" Watch "HttpServletResponse content size?" New topic
Author

HttpServletResponse content size?

Ralf Rottmann
Greenhorn

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="http://www.rottmann.net" target="_blank" rel="nofollow">http://www.rottmann.net</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
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
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

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: 8904

Check the example under Programming Customized Requests and Responses
http://java.sun.com/products/servlet/Filters.html


Groovy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpServletResponse content size?
 
Similar Threads
Query String in Request Dispatcher
url not supported
go to a web url using java code
why should HttpServletResponse.sendRedirect lead to a blank page?
how to set environment variables for running a servlet program?