Search code examples
tomcatgrailscharacter-encodinggrails-orm

Grails request parameters encoding issue in Tomcat


My grails app will not decode request parameters correctly.

In config.groovy:

  • grails.views.gsp.encoding = "UTF-8"
  • grails.converters.encoding = "UTF-8"

All my gsp's use contentType="text/html; charset=UTF-8" on the page directive as well as <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> in the head element.

However, when i receive the posted parameters from the param object in my controller, the app just prints garbage...

I'm using Grails 1.3.7 version deployed over Tomcat 5. Other installed plugins except tomcat:

hibernate 1.3.7 jquery 1.7.1 spring-security-core 1.2.6 webxml 1.4

EDIT: From further debugging, i've noticed that the app will run fine in jetty. Therefore i suspect it must be a tomcat issue. My issue is similar to this post (alas i'm not using the Shiro plugin).

Can anyone help with this?


Solution

  • You need to add URIEncoding='UTF-8' to the Connector elements in conf/server.xml, e.g.

    <Connector port='8080' protocol='HTTP/1.1' connectionTimeout='20000'
               redirectPort='8443' URIEncoding='UTF-8' />
    

    This is described here: https://wiki.apache.org/tomcat/FAQ/CharacterEncoding