848 |
30 Jun 05 |
nicklas |
1 |
|
848 |
30 Jun 05 |
nicklas |
How to configure MySQL and Tomcat to support unicode |
848 |
30 Jun 05 |
nicklas |
3 |
==================================================== |
848 |
30 Jun 05 |
nicklas |
4 |
|
848 |
30 Jun 05 |
nicklas |
The BASE core and web client supports unicode, but to take |
848 |
30 Jun 05 |
nicklas |
advantage of that the database and the servlet container must |
848 |
30 Jun 05 |
nicklas |
also be correctly configured. This document describes how to configure |
848 |
30 Jun 05 |
nicklas |
MySQL and Tomcat to fully support unicode using the UTF-8 character |
848 |
30 Jun 05 |
nicklas |
encoding. The configuration should be done BEFORE installing and |
848 |
30 Jun 05 |
nicklas |
building the database. |
848 |
30 Jun 05 |
nicklas |
11 |
|
848 |
30 Jun 05 |
nicklas |
12 |
|
848 |
30 Jun 05 |
nicklas |
MySQL |
848 |
30 Jun 05 |
nicklas |
14 |
----- |
848 |
30 Jun 05 |
nicklas |
There are two steps that must be done BEFORE the BASE |
848 |
30 Jun 05 |
nicklas |
server is installed: |
848 |
30 Jun 05 |
nicklas |
17 |
|
848 |
30 Jun 05 |
nicklas |
1. Make sure the database tables can handle UTF-8 data. |
848 |
30 Jun 05 |
nicklas |
This easiest done when you create the database by adding |
848 |
30 Jun 05 |
nicklas |
a default character encoding to the CREATE DATABASE statment, |
848 |
30 Jun 05 |
nicklas |
for example: |
848 |
30 Jun 05 |
nicklas |
22 |
|
848 |
30 Jun 05 |
nicklas |
CREATE DATABASE base2 DEFAULT CHARACTER SET utf8; |
848 |
30 Jun 05 |
nicklas |
24 |
|
848 |
30 Jun 05 |
nicklas |
2. Make sure the JDBC connection uses UTF-8 as the character set |
848 |
30 Jun 05 |
nicklas |
to communicate with the database. This is done by specifying it |
848 |
30 Jun 05 |
nicklas |
in the db.url property in the base.config file: |
848 |
30 Jun 05 |
nicklas |
28 |
|
2940 |
21 Nov 06 |
nicklas |
db.url = jdbc:mysql://127.0.0.1/base2?characterEncoding=UTF-8 |
848 |
30 Jun 05 |
nicklas |
30 |
|
2940 |
21 Nov 06 |
nicklas |
Note that in the SQL statement you should use 'utf8' but in the |
2940 |
21 Nov 06 |
nicklas |
connection string you should use 'UTF-8'. If 'UTF-8' doesn't work |
2940 |
21 Nov 06 |
nicklas |
in the connection string you may try using 'utf8' there as well. |
2940 |
21 Nov 06 |
nicklas |
In our original test only 'utf8' worked but we have got reports |
2940 |
21 Nov 06 |
nicklas |
stating that now only 'UTF-8' works. If you are using another |
2940 |
21 Nov 06 |
nicklas |
database than MySQL you have to look in the documentation for that |
2940 |
21 Nov 06 |
nicklas |
database how to enable unicode support. |
848 |
30 Jun 05 |
nicklas |
38 |
|
848 |
30 Jun 05 |
nicklas |
Tomcat |
848 |
30 Jun 05 |
nicklas |
40 |
------ |
848 |
30 Jun 05 |
nicklas |
Again, there are two steps that must be done: |
848 |
30 Jun 05 |
nicklas |
42 |
|
848 |
30 Jun 05 |
nicklas |
1. Change the character encoding parameter in the web.xml file. |
848 |
30 Jun 05 |
nicklas |
The web.xml file is located in the BASE_HOME/www/WEB-INF |
848 |
30 Jun 05 |
nicklas |
directory. In the bottom of that file you will find a <filter> |
848 |
30 Jun 05 |
nicklas |
tag with the name "characterEncoding". Change the value |
848 |
30 Jun 05 |
nicklas |
of the <param-value> tag to UTF-8: |
848 |
30 Jun 05 |
nicklas |
48 |
|
848 |
30 Jun 05 |
nicklas |
<filter> |
848 |
30 Jun 05 |
nicklas |
<filter-name>characterEncoding</filter-name> |
848 |
30 Jun 05 |
nicklas |
<filter-class> |
848 |
30 Jun 05 |
nicklas |
net.sf.basedb.clients.web.servlet.CharacterEncodingFilter |
848 |
30 Jun 05 |
nicklas |
</filter-class> |
848 |
30 Jun 05 |
nicklas |
<init-param> |
848 |
30 Jun 05 |
nicklas |
<param-name>characterEncoding</param-name> |
848 |
30 Jun 05 |
nicklas |
<param-value>UTF-8</param-value> |
848 |
30 Jun 05 |
nicklas |
</init-param> |
848 |
30 Jun 05 |
nicklas |
</filter> |
848 |
30 Jun 05 |
nicklas |
59 |
|
848 |
30 Jun 05 |
nicklas |
2. You must also edit the server.xml found in Tomcats configuration |
848 |
30 Jun 05 |
nicklas |
directory, TOMCAT_HOME/conf. In this file you must add the |
848 |
30 Jun 05 |
nicklas |
useBodyEncodingForURI="true" attribute to the <Connector> tag: |
848 |
30 Jun 05 |
nicklas |
63 |
|
848 |
30 Jun 05 |
nicklas |
<Connector port="8080" |
848 |
30 Jun 05 |
nicklas |
...lots of other attributes... |
848 |
30 Jun 05 |
nicklas |
useBodyEncodingForURI="true" |
848 |
30 Jun 05 |
nicklas |
67 |
/> |
848 |
30 Jun 05 |
nicklas |
68 |
|
848 |
30 Jun 05 |
nicklas |
If you are using another servlet container than Tomcat you should |
848 |
30 Jun 05 |
nicklas |
look in the documentation for that container how to make the configuration |
848 |
30 Jun 05 |
nicklas |
in step 2. |