5

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?

Lefteris Laskaridis
  • 2,292
  • 2
  • 24
  • 38

3 Answers3

9

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

Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
  • Thanks for your reply. My problem is with POST parameters actually. If i understood the FAQ correctly URIEncoding applies to GET parameters only. Nevertheless, i gave it a shot but didn't work either. It might be a long shot but could it be the order of filters in my generated web.xml? In there i have the following filters in that order: springSecurityFilterChain -> sitemesh -> charEncodingFilter -> urlMapping -> hiddenHttpMethod -> grailsWebRequest – Lefteris Laskaridis Feb 10 '12 at 11:52
  • Sorry, I didn't catch that you're using webxml 1.4 - you need to use 1.4.1 which fixes this charEncodingFilter order bug. You also need to upgrade to a later version of Spring Security Core, so you should use 1.2.7.2 (the latest). – Burt Beckwith Feb 10 '12 at 15:02
  • @BurtBeckwith Is there a way to set this `URIEncoding` to `UTF-8` directly in Grails so that we don't have to apply this change to tomcat in each server? – Shashank Agrawal Oct 14 '15 at 13:17
  • No, you can't configure the server from inside a war file. – Burt Beckwith Oct 14 '15 at 16:17
0
edit application.properties
add(update) line:
plugins.webxml=1.4.1
talha2k
  • 24,937
  • 4
  • 62
  • 81
0

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.

zisoft
  • 22,770
  • 10
  • 62
  • 73
Igors23m
  • 1
  • 1