GRAILS does not have the correct encoding Unicode character

In my grails application, unicode characters are not correctly encoded.

I use grails 1.3.7 and tomcat 7.0.22. Below This is the setting I configured for unicode support in my application:

- Set grails.views.gsp.encoding and grails.converters.encoding="UTF-8" in Config.groovy
- Set encoding to UTF-8 in meta tag in the .gsp pages
- Specified'useUnicode=true&characterEncoding=UTF-8' to the MySql connection URL (DB has characterset set to UTF- 8)
- Set URIEncoding="UTF-8" useBodyEncodingForURI="true" to the server.xml file in tomcat
- Specified the attribute accept-charset="UTF-8" of the form tag.

But when I submit a unicode character, grails does not support the character and is saving garbled values. I have googled a bit and have read ppl asking for help on the same issue but unfortunately These solutions are not suitable for me. Although, I found a solution to this problem. The following expressions

params.detail = params.detail? New String(params.detail .getBytes("8859_1"), "UTF8"): null

Unicode characters will be correctly encoded.

However, using this method is cumbersome, because I have to apply All text input in the program performs this operation. Why are unicode characters not properly encoded by grails and/or tomcat? I think my settings are correct.

If you are not using Mysql, but the HSqlDB provided by default, You will not see
Your encoding problem. There is a problem due to Mysql, InnoDB and UTF-8.

Because you are using Mysql Connection and it has been set up
useUnicode = true& characterEncoding = UTF-8 to MySql connection URL

You still need to add a special hibernate dialect for InnoDB and UTF-8:

Datasource.groovy should contain:

p>

environments {
development {
dataSource {
......
driverClassName = "com.mysql.jdbc.Driver "
dialect = "com.domain.mysql.dialect.MySQLUTF8InnoDBDialect"
.....

In src / java / com / domain / mysql / dialect / MySQLUTF8InnoDBDialect.java Create a new file in

package com.domain.mysql.dialect;

import org.hibernate.dialect.MySQLInnoDBDialect;
< br />/**
* Sets the default charset to UTF-8.
*/
public class MySQLUTF8InnoDBDialect extends MySQLInnoDBDialect {

@Override
public String getTa bleTypeString() {
return "ENGINE=InnoDB DEFAULT CHARSET=utf8";
}
}

Make sure your Config.groovy has:

grails.views.default.codec = "html"
grails.views.gsp.encoding = "UTF-8"
grails.converters.encoding = "UTF-8 "

Your views/layouts/main.gsp are:

<%@ page contentType="text/html;charset=UTF-8" %>

Come in sight,

January

In my grails application, unicode characters are not correctly encoded .

I use grails 1.3.7 and tomcat 7.0.22. The following are the settings I configured for unicode support in my application:

- Set grails.views.gsp.encoding and grails.converters.encoding="UTF-8" in Config.groovy
- Set encoding to UTF-8 in meta tag in the .gsp pages
- Specified'useUnicode=true&characterEncoding=UTF-8' to the MySql connection URL (DB has characterset set to UTF-8)
- Set URIEncoding="UTF-8" useBodyEncodingForURI="true" to the server. xml file in tomcat
- Specified the attribute accept-charset="UTF-8" of the form tag.

However, when I submit a unicode character, gr ails does not support the character and is saving garbled values. I have googled and read ppl asking for help on the same issue but unfortunately these solutions are not suitable for me. Although, I found a solution to this problem Method. The following expression

params.detail = params.detail? New String(params.detail.getBytes("8859_1"), "UTF8"): null

Unicode characters will be correctly encoded.

However, using this method is tedious because I have to do this for all text input in my application. Why are unicode characters not being grailed and / Or tomcat is correctly coded? I think my settings are correct.

If you are not using Mysql, but the HSqlDB provided by default, you will not see
your coding problems .There are problems due to Mysql, InnoDB and UTF-8.

Because you are using Mysql Connection and have been set up
useUnicode = true& characterEncoding = UTF-8 to MySql connection URL

You still need to add a special hibernate dialect for InnoDB and UTF-8:

Datasource.groovy should contain:

 environments {
development {
dataSource {
......
driverClassName = "com.mysql.jdbc.Driver"
dialect = "com.domain. mysql.dialect.MySQLUTF8InnoDBDialect"
.....

Create a new file in src/java/com/domain/mysql/dialect/MySQLUTF8InnoDBDialect.java

package com.domain.mysql.dialect;

import org.hibernate.dialect.MySQLInnoDBDialect;

/**
* Sets the default charset to UTF-8.
*/
public class MySQLUTF8InnoDBDialect extends MySQLInnoDBDialect {

@Override
public String getTableTypeString() {
return " ENGINE=InnoDB DEFAUL T CHARSET=utf8";
}
}

Make sure your Config.groovy has:

grails.views.default .codec = "html"
grails.views.gsp.encoding = "UTF-8"
grails.converters.encoding = "UTF-8"

Your views / layouts / main.gsp starts with:

<%@ page contentType="text/html;charset=UTF-8" %>

January

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4918 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.