users@glassfish.java.net

Re: encoding still not working :(

From: BJörn Lindqvist <bjourne_at_gmail.com>
Date: Wed, 18 Mar 2009 17:20:17 +0100

2009/3/17 Wolfram Rittmeyer <w.rittmeyer_at_jsptutorial.org>:
> Actually internationalization on the web is a big mess. E.g.: AFAIK all
> browsers use the encoding of the page (META-html tag) when creating a URL
> for GET requests after submitting a form - even though the W3C and rfc2718
> state to always use UTF-8. Also it is unfortunate that the servlet spec
> defaults to ISO-8859-1.

That is not entirely true. Glassfish, by default, sets the
Content-Type charset header to ISO-8859-1 which causes browsers to
send data in ISO-8859-1 encoding even if you specify another encoding
in the meta tag. So the browser submits ISO-8859-1 strings which the
server erroneously believes is UTF-8 if you have set
<parameter-encoding default-charset="UTF-8"/> for example. Then when
the server tries to display that data, it encodes it as UTF-8 which
produces garbled strings because they are still in ISO-8859-1.

The solution, which forces the browser to submit forms in UTF-8, is to
use the following jsp tag:

<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>

It would be more convenient if there was a domain setting to set the
default HTTP Content-Type header to UTF-8, but there doesn't seem to
be any.

> Thus no matter what the wiki page says, the issue will remain confusing.
> Nevertheless I guess the page could be improved. Maybe I can suggest s.th.
> tomorrow.

That wiki page deals only with request encodings. That is, how the
glassfish server interprets strings coming from the user, not the
encoding of the strings it sends to the user.


-- 
mvh Björn