-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Oscar,
On 3/27/2009 10:35 AM, Je suis la poubelle wrote: > 1. In those mentioned web pages, I noticed that none of them explicitly > specified the following HTML header: > <head> > <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> > </head> That's because setting a META tag that doesn't match reality is not really a good idea. I can set the charset to shift-js in the META tag but it doesn't mean the page is actually in Japanese. > And what if another encoding is specified in HTML header, say > ISO-8859-1? Which one would the browser use in priority? Nobody knows the > answer! Actually, everybody knows the answer, because it's published in the HTML specification: http://www.w3.org/TR/html4/charset.html#h-5.2.2 " To sum up, conforming user agents must observe the following priorities when determining a document's character encoding (from highest priority to lowest): 1. An HTTP "charset" parameter in a "Content-Type" field. 2. A META declaration with "http-equiv" set to "Content-Type" and a value set for "charset". 3. The charset attribute set on an element that designates an external resource. " > That's why I specify the encoding in both places. While it's not a terrible idea to specify the encoding in both places, you should consider the possibility that the META tag can be wrong. > 2. To make things easier for myself, I always save JSP files in UTF-8 > encoding, and I always put this header as well: > <%@ page pageEncoding="utf-8" %> > Now everything's in UTF8 from A to Z. If you're following guidelines for i18n, you'll put your non-ASCII strings into property files and won't have to worry about the encoding of the JSP source file. > String sUTF8 = new String(sWrongEncoding.getBytes("iso-8859-1"), "UTF8"); I think that should be "rightString", not "sUTF8", since the String object has no inherent encoding. - -chris PS http://en.wikipedia.org/wiki/Oscar_the_grouch -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAknM8egACgkQ9CaO5/Lv0PBfDwCcDMdG7t2H6vKJZbzhj/y9CJAy saUAoK+YrOSmkYDa9/2E24RIwB6UF8tI =rE0n -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org