Grails request parameters encoding issue in Tomcat

2019-01-25 19:03发布

问题:

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?

回答1:

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



回答2:

edit application.properties
add(update) line:
plugins.webxml=1.4.1


回答3:

As fas as no final conclusion made, I'd like to share my expierence in the same situation. Here one can find more discussion.

I my case, I have dev environment under the windows on local pc including local MySQL. Production env - Centos 6, MySQL, Tomcat 6 behind Apache.

In dev environment - everything was o'k, but on production - no. The only thing that help me - was set autoreconnect=true&useUnicode=true&characterEncoding=UTF-8 additionally to recommendations both for Tomcat URIEncoding='UTF-8'

So, the problem was in correct settings java Driver for MySQL.