1 | |
---|
2 | How to configure MySQL and Tomcat to support unicode |
---|
3 | ==================================================== |
---|
4 | |
---|
5 | The BASE core and web client supports unicode, but to take |
---|
6 | advantage of that the database and the servlet container must |
---|
7 | also be correctly configured. This document describes how to configure |
---|
8 | MySQL and Tomcat to fully support unicode using the UTF-8 character |
---|
9 | encoding. The configuration should be done BEFORE installing and |
---|
10 | building the database. |
---|
11 | |
---|
12 | |
---|
13 | MySQL |
---|
14 | ----- |
---|
15 | There are two steps that must be done BEFORE the BASE |
---|
16 | server is installed: |
---|
17 | |
---|
18 | 1. Make sure the database tables can handle UTF-8 data. |
---|
19 | This easiest done when you create the database by adding |
---|
20 | a default character encoding to the CREATE DATABASE statment, |
---|
21 | for example: |
---|
22 | |
---|
23 | CREATE DATABASE base2 DEFAULT CHARACTER SET utf8; |
---|
24 | |
---|
25 | 2. Make sure the JDBC connection uses UTF-8 as the character set |
---|
26 | to communicate with the database. This is done by specifying it |
---|
27 | in the db.url property in the base.config file: |
---|
28 | |
---|
29 | db.url = jdbc:mysql://127.0.0.1/base2?characterEncoding=UTF-8 |
---|
30 | |
---|
31 | Note that in the SQL statement you should use 'utf8' but in the |
---|
32 | connection string you should use 'UTF-8'. If 'UTF-8' doesn't work |
---|
33 | in the connection string you may try using 'utf8' there as well. |
---|
34 | In our original test only 'utf8' worked but we have got reports |
---|
35 | stating that now only 'UTF-8' works. If you are using another |
---|
36 | database than MySQL you have to look in the documentation for that |
---|
37 | database how to enable unicode support. |
---|
38 | |
---|
39 | Tomcat |
---|
40 | ------ |
---|
41 | Again, there are two steps that must be done: |
---|
42 | |
---|
43 | 1. Change the character encoding parameter in the web.xml file. |
---|
44 | The web.xml file is located in the BASE_HOME/www/WEB-INF |
---|
45 | directory. In the bottom of that file you will find a <filter> |
---|
46 | tag with the name "characterEncoding". Change the value |
---|
47 | of the <param-value> tag to UTF-8: |
---|
48 | |
---|
49 | <filter> |
---|
50 | <filter-name>characterEncoding</filter-name> |
---|
51 | <filter-class> |
---|
52 | net.sf.basedb.clients.web.servlet.CharacterEncodingFilter |
---|
53 | </filter-class> |
---|
54 | <init-param> |
---|
55 | <param-name>characterEncoding</param-name> |
---|
56 | <param-value>UTF-8</param-value> |
---|
57 | </init-param> |
---|
58 | </filter> |
---|
59 | |
---|
60 | 2. You must also edit the server.xml found in Tomcats configuration |
---|
61 | directory, TOMCAT_HOME/conf. In this file you must add the |
---|
62 | useBodyEncodingForURI="true" attribute to the <Connector> tag: |
---|
63 | |
---|
64 | <Connector port="8080" |
---|
65 | ...lots of other attributes... |
---|
66 | useBodyEncodingForURI="true" |
---|
67 | /> |
---|
68 | |
---|
69 | If you are using another servlet container than Tomcat you should |
---|
70 | look in the documentation for that container how to make the configuration |
---|
71 | in step 2. |
---|