I was surprised to find out Jboss (Tomcat) servlet container does not use UTF-8 URI encoding by default. What this means is, in a web application running under JBoss or Tomcat, query strings in GET requests that contain multi-byte UTF-8 encoded characters (Chinese or Japanese characters, for example) will not be decoded accurately on server side.
I ran into this issue on the target page of a POST-REDIRECT-GET invocation. The requirement was to display some user data on the target page and the data was being passed as query string of the GET call. I could see that the query string was properly URI-encoded, but it was not getting displayed properly on the target page. Upon investigating, I figured out this is neither an application bug nor a limitation of the web framework that was being used (Struts 2 in this case). The culprit was JBoss’s servlet container, which was not using UTF-8 decoding on query strings.
Here is how you fix this problem. Locate server.xml configuration file used by the JBoss server. You will find it under <JBoss home>/server/<server-name>/deploy/jboss-web.deployer. If you are using plain Tomcat, you will find this under <Tomcat home>/conf. Add the attribute URIEncoding=”UTF-8″ to the appropriate connector element and re-start the server. That should do the trick!
March 9, 2012 at 10:02 pm |
Thank you so much for pointing to this. Actually, I have same problem where the redirect-get was creating junk chinese characters. I had the URIEncoding set which caused the problem and once I removed it, it is working fine