In my grails app, the unicode characters are not being encoded properly.
I\'m using grails 1.3.7 and tomcat 7.0.22. Following are the settings that I\'ve configured
If you are not using Mysql but the HSqlDB which is shipped as default, you will not see your encoding problems. The problems occurs due to Mysql, InnoDB and UTF-8.
Since you are using a Mysql Connection and already setting
useUnicode=true&characterEncoding=UTF-8 to the MySql connection URL
you still have 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 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"
And your views/layouts/main.gsp starts with:
<%@ page contentType="text/html;charset=UTF-8" %>
Greets,
Jan