Skip to main content

[webtier] Re: encoding still not working :(

1 reply [Last post]
Anonymous

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Jan Luehe

BJörn,

On 03/18/09 09:20 AM, BJörn Lindqvist wrote:
> 2009/3/17 Wolfram Rittmeyer :
>
>> 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

You're right.
See my reply to Ken ("Re: why the default response character encoding
must be ISO-8859-1?"),
sent to the users@glassfish alias, for the motivation behind this, and
why the Servlet 2.5 actually
requires this behaviour.

> 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
>
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" %>
>

Exactly!
> 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.
>

Correct, there is no domain setting for this, because each webapp is
different.
However, you could declare the above page directive in a JSP prelude
(which in
turn would have to be declared in your web.xml), in order to avoid having to
declare it on each and every of your JSPs.

Hope this help.

Thanks,

Jan

>
>> 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.
>
>
>

[att1.html]