. 统一编码
从Tomcat 到 Mysql,我选择了gbk编码,因为实在Windows平台下,在Linux下通常设置为ISO-8895-1。
2. Tomcat 5配置,让URL支持中文
在Server.xml文件中,只需添加Connector的URIEncoding参数即可,默认情况下该参数未被配置。要支持URL参数支持中文,加上URIEncoding=”GBK”就行。
<Connector port="80"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="GBK"/>
3. JSP
在每个JSP页面中保证一下代码的存在:
<%@ page contentType="text/html; charset=gbk"%>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
4. Servlet
在Servlet中,一定要在doGet或doPost的一开始就加入以下代码:
request.setCharacterEncoding("gbk";
response.setContentType("text/html; charset=gbk";
5. MySql
Varchar 或Char类型的列一定要把编码方式设定为gbk,在MyManager Pro中输入的中文只能在MyManager Pro中看到,用程序调用就不知道是什么了,可能跟MyManager Pro的编码有关,同样通过网页传入的中文,在MyManager Pro也只能看到问号。
另外注明,Mysql不支持中文的全文检索,因为没有中文智能分词能力,4.1的版本有个叫海量的公司做了中文全文检索的版本,但是5.0以上版本还没有办法支持中文全文检索。
6. Connection connection = DriverManager
.getConnection("jdbc:mysql://localhost:3306/mysql1?user=root&password=1&useUnicode=true&characterEncoding=GBK");