views:

22

answers:

1

One of the request parameters in an http request made by the client contains Japanese characters. If I make this request in Firefox and look at the parameter as soon as it reaches the server by debugging in Eclipse, the characters look fine. If I do the same request using IE 8, the characters get garbled when I look at them at the same point in the server code (they are fine in both browsers, though). I have examined the POST requests made by both browsers, and they both pass the same sequence of characters, which is:

%2C%E3%81%9D%E3%81%AE%E4%BB%96

I am therefore thinking that this has to do with the encoding. If I look at the HTTP headers of the request, I notice the following differences. In IE:

Content-Type: application/x-www-form-urlencoded
Accept: */*

In Firefox:

Content-Type application/x-www-form-urlencoded; charset=UTF-8
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7

I'm thinking that the IE 8 header doesn't state the UTF-8 encoding explicitly, even though it's specified in the meta tag of the HTML document. I am not sure if this is the problem. I would appreciate any help, and please do let me know if you need more information.

A: 

Make sure the page that contains the form has UTF-8 as charset. In IE's case, the best thing to make sure of this is by sending a HTTP header ('Content-Type: text/html; charset=utf-8') and adding a meta http-equiv tag with the content type/charset to your html (I've seen this actually matter, even when the appropriate header was sent).

Second, your form can also specify the content type:

<form enctype="application/x-www-form-urlencoded; charset=utf-8>
Peter Kruithof
The request is made via an AJAX call, and I just modified that call so that it specifies the UTF-8 charset, so that now both IE and Firefox have "application/x-www-form-urlencoded; charset=utf-8" as the Content-Type. Now, if I look at the characters in Eclipse, they are not garbled anymore. But now they appear as squares when they get rendered back to IE, while they are fine in Firefox. By "rendered", I mean the characters appear in a chart generated by JFreeCharts. I would appreciate any other suggestions.
Agustin
Working with UTF-8 is all about keeping each and every aspect of your request/response chain UTF-8 encoded: your pages, but also your database (and database connections!). A square typically indicates that somewhere, something is not set to UTF-8. In this case I would suspect the page you're viewing, since Firefox shows the characters right. Check in IE what the page's content type is (right click > page info, or something).
Peter Kruithof