Michael Ludwig schrieb am 20.11.2008 um 01:58:20 (+0100): > > > > String s = "<!-- Huhu -->" + wrapper.toString(); > > > ( (HttpServletResponse) res).setHeader( > > > "Zeichen", Integer.toString( s.length())); > > > > Note that this may not be correct: other filters could be adding > > content, and Content-Length is in bytes, not characters. If you are > > using anything other than ASCII, then this will not be correct. > > Very true.
Or partly true. I wrote "Zeichen" (characters), not "Oktette" (octets, or bytes), so str.length() is alright. :-) Unless I have to deal with Unicode surrogate pairs (which fortunately I don't). In that exotic case, str.codePointCount() would be required. John O'Conner's Blog: How long is your String? http://weblogs.java.net/blog/joconner/archive/2005/08/how_long_is_you.html In addition to ASCII, the string.length() approach should also work for 8-bit encoding schemes like ISO-8859-1. SUN simplified like this in their Filters tutorial. response.setContentLength(caw.toString().length()); http://java.sun.com/products/servlet/Filters.html When I have to handle Content-Length myself, for outputting, say, "Käsekuchen", and I may have chosen UTF-8, looks like I have to use: str.getBytes( response.getCharacterEncoding()).length But as you wrote, unbeknownst to it, my filter may itself be subject to filtering, so it may not know the definitive answer. It should probably only set the Content-Length if there is none set yet and else only apply the delta of what it adds or takes away to the value already set. Or rather, this should be handled per webapp as suitable, and there is no general rule. Michael Ludwig --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]