dipess
dipess

Reputation: 33

Grails not able to decode the unicode characters

I have following configurations for a Grails app:

  1. Grails 1.3.7
    Set the following in the config.groovy file
    grails.views.default.codec="none"
    grails.views.gsp.encoding="UTF-8"
    grails.converters.encoding="UTF-8"

  2. Tomcat 7.0.22
    Set the following in the server.xml file for tomcat
    URIEncoding="UTF-8" useBodyEncodingForURI="true"

And, in my gsp page, I've set charset=UTF-8" since I want to use the UTF-8 character encoding.

Then, in any of the input box when I enter a unicode character and submit the form and check for the parameter dump at the associated action in the controller, the unicode character is garbled. Checking the browser request to the server using the Firebug shows the unicode character being correctly encoded and submitted to the server.

But still, if I do sth. like params.unicodeInput = new String(params.unicodeInput.getBytes("8859_1"), "UTF8");

the unicode character is correctly decoded. I wanted to know why the unicode characters are not being correctly decoded on a normal browser request although the browser correctly sends the unicode characters.

Thanks!!

Edit
I created a demo app with the same configuration and everything seems fine on the demo app. This problem exists only in this particular app. Could it be due to some other installed plugins?

And printing the request.getCharacterEncoding() and response.getCharacterEncoding() both yields to UTF-8.

Upvotes: 3

Views: 2310

Answers (1)

Andrej Istomin
Andrej Istomin

Reputation: 3043

I'm not sure, but when I had unicode problems with Grails + Tomcat, I solved the problem adding the following parameters to Tomcat's setenv.sh: JAVA_OPTS="-Djavax.servlet.request.encoding=UTF-8 -Dfile.encoding=UTF-8"

Upvotes: 4

Related Questions