Reputation: 11
While testing my app, I noticed the following issue where a string containing a unicode character, when passed to the controller and then back to the page, becomes garbled - or at least is not represented consistently - from the user's perspective.
1. Xáeso
2. Xßeso
3. X%E1eso
RequestParam
from the page to the controller.RequestParam
in the controllerThis is the only valid representation of the text as far as what the user would expect to see:
1. Xáeso
How can I ensure that the unicode character in position 2 of this string is represented consistently to the client-side user of the app?
Upvotes: 1
Views: 164
Reputation: 597076
There are multiple places where encoding can go wrong.
A quick fix might be to use spring's CharacterEncodingFilter
(or the equivalent interceptor), and set the encoding to utf-8
. Also, your JSP pages better have <%@ page pageEncoding="utf8" %>
Upvotes: 1
Reputation: 718768
My guess is that part of the problem is that the web server (e.g. Tomcat) is using the wrong character set when translating the request parameters into UTF-16.
If you are using Tomcat, read the Character Encoding FAQ, and check each of the issues listed. (Pay particular attention to the bit that talks about the effects of filters and valves ...)
Upvotes: 0