You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Vermeulen, Francis" <Fr...@atosorigin.com> on 2003/01/22 15:03:52 UTC

request.setCharacterEncoding(charset) problem?

Hi,

we are using Tomcat 4.1.12 in a Windows 2000 development environment and
Tomcat 4.0.3 in a Solaris production environment.

We have a JSP page that handles search queries and is supposed to be
internationalized. The JSP page makes sure to set the "UTF-8" charset so
that the browser wil use this encoding for the FORM parameters in the POST
request. Inside the JSP page, the method
request.setCharacterEncoding("UTF-8") is used before using
request.getParameter() so as to ensure that Tomcat decodes the POST
bytestring as UTF-8 (instead of the default ISO-8859-1).

The problem I have, is that the behaviour under Windows is different from
that under Solaris: on my Windows platform, the
request.setCharacterEncoding("UTF-8") does not seem to have any effect at
all, i.e. when I send a "ü"  character (0xFC), it still gets decoded as two
separate characters by Tomcat as ISO-8859-1. On the Solaris platform, it
seems to work fine...

Did anyone encountered the same problem or knows of this? Or do do I have to
go and look into the Tomcat source code?

Any light shed on this would be very helpfull, thanks!

Regards,

============================================
Ing. FRA Vermeulen
Senior J2EE Architect
ECM Solutions - Eindhoven
mobiel: +31 (0) 6 222 03 856
e-mail: francis.vermeulen@atosorigin.com
============================================



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: request.setCharacterEncoding(charset) problem?

Posted by Daniel Brown <gm...@blueyonder.co.uk>.
Francis,

The HTML (4.01) spec says that browsers 'may' use the page encoding as the
encoding to use when submitting form data. If you're assuming UTF-8, then
you might want to consider something like the following,

<FORM accept-charset="UTF-8" ... >
...
</FORM>

to force conforming browsers do the right thing.

Also, I think that parameters are decoded within Tomcat as ISO-8859-1 (or
your default charset?), no matter what, so you'll need to do something like
the following too:

 byte[] b = param.getBytes("ISO-8859-1"); // Give us back the bytes
 param = new String(b, "UTF-8"); // Interpret them correctly, this time.

Bring on the day UTF-8 is the standard for all of this.

Dan.

> Hi,
>
> we are using Tomcat 4.1.12 in a Windows 2000 development environment and
> Tomcat 4.0.3 in a Solaris production environment.
>
> We have a JSP page that handles search queries and is supposed to be
> internationalized. The JSP page makes sure to set the "UTF-8" charset so
> that the browser wil use this encoding for the FORM parameters in the POST
> request. Inside the JSP page, the method
> request.setCharacterEncoding("UTF-8") is used before using
> request.getParameter() so as to ensure that Tomcat decodes the POST
> bytestring as UTF-8 (instead of the default ISO-8859-1).
>
> The problem I have, is that the behaviour under Windows is different from
> that under Solaris: on my Windows platform, the
> request.setCharacterEncoding("UTF-8") does not seem to have any effect at
> all, i.e. when I send a "ü"  character (0xFC), it still gets
> decoded as two
> separate characters by Tomcat as ISO-8859-1. On the Solaris platform, it
> seems to work fine...
>
> Did anyone encountered the same problem or knows of this? Or do
> do I have to
> go and look into the Tomcat source code?
>
> Any light shed on this would be very helpfull, thanks!
>
> Regards,
>
> ============================================
> Ing. FRA Vermeulen
> Senior J2EE Architect
> ECM Solutions - Eindhoven
> mobiel: +31 (0) 6 222 03 856
> e-mail: francis.vermeulen@atosorigin.com
> ============================================
>
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>