开发者

google maps character encoding problem

I get a map, from java, asking for him with the next sentence:

<a href="http://maps.google.com/maps?q=<%=(infoHotel.getHotelType().getHotelTypeDescription() == null ? "" :infoHotel.getHotelType().getHotelTypeDescription()) + "+" + (infoHotel.getHotelName() == null ? "" : infoHotel.getHotelName())%>@<%=lat%>,<%=lon%>&ie=UTF-8&oe=UTF-8&=13&hl=<%=langmap%>" 开发者_如何学JAVAtarget="_blank" style="color:#000000">

It goes perfect. But when I click on the Enlarge Map link of the Google Map, I get the next, deppending on if the nav is IE, Firefox or Chrome. I put a kind of table to you:

IE: url bar: http://maps.google.com/maps?q=HÔTEL+TRYP BARCELO AEROPUERTO@41.31178725510836,2.0692870393395424&ie=UTF-8&oe=UTF-8&z=13&hl=es

search bar: H?TEL TRYP BARCELO AEROPUERTO@41.31178725510836,2.0692870393395424

Chrome: url bar: http://maps.google.com/maps?q=H%C3%94TEL+TRYP%20BARCELO%20AEROPUERTO@41.31178725510836,2.0692870393395424&ie=UTF-8&oe=UTF-8&z=13&hl=es

search bar: HÔTEL TRYP BARCELO AEROPUERTO@41.31178725510836,2.0692870393395424

FireFox: url bar: http://maps.google.com/maps?q=H%D4TEL+TRYP%20BARCELO%20AEROPUERTO@41.31178725510836,2.0692870393395424&ie=UTF-8&oe=UTF-8&z=13&hl=es

search bar: H?TEL TRYP BARCELO AEROPUERTO@41.31178725510836,2.0692870393395424

Note that Chrome is the only one that works perfectly. "Hôtel" and "Hôtel", both in url bar and search bar. But see what's doing with IE or FireFox.

The JSP line is the one all above, the others I took them making copy+paste.

Can anyone help me please?


Firstly, it isn't enough to look at the address bar to diagnose this. Some browsers display one thing (un-encoded) in the address bar but send something different (encoded) in the HTTP request. To be absolutely sure what is being sent to the server review the actual request on the wire using FireBug or equivalent.

Also, be aware that percent encoding is charset-specific. That is to say, percent encoding with UTF-8 is not the same as percent encoding with iso-8859-1.

When browsers make requests they tend to use the charset of the current page to encode the response. This is true for multipart form submission, etc. If you have failed to specify the encoding of the page with the anchor tag the browser will guess an encoding (often iso-8859-1). In your case Firefox seems to have chosen iso-8859-1 (or UTF-16) while Chrome has chosen UTF-8.

See details of the Ô char here: http://www.fileformat.info/info/unicode/char/d4/index.htm

Also, it seems that you're specifying UTF-8 encoding as a parameter in your request.

I would suggest changing your JSP to ensure:

  1. Content on the page with the anchor tag is encoded as UTF-8.
  2. You're sending an appropriate Content-Type header (and/or meta tag) to let the browser know the page is UTF-8.


About the URL - you cannot place non-ASCII characters in a URL, you should perform URL Encoding on them before returning them. Also, spaces are illegal and should be URL encoded as well (A space is encoded as %20)

Chrome and FireFox might be smart enought to perform URL Encoding for you, but it is not the standard of a browser to do so.

About the search bar - how do you place the result there? do you copy paste it yourself or do you do it problematically?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜