如果MySQL,J2EE平台的中文处理出现问题,则请从以下几方面考虑: A、数据库配置文件my.ini [mysqld] default-characterset=utf8 或 character-set-server=utf8 B、mysql-ds.xml,以下为部分相关内容 <?xml version='1.0' encoding='UTF-8'?> <datasources> <local-tx-datasource> <jndi-name>MySqlDS</jndi-name> <connection-url> jdbc:mysql://localhost:3306/uplatform </connection-url> <connection-propertyname='characterEncoding'>utf8</connection-property> <driver-class>com.mysql.jdbc.Driver</driver-class> <user-name>kzz</user-name> <password>118200</password> ... ... ... </datasources> C、数据库建表请用utf8为字符集 D、JSP请用UTF-8或GB2312为编码方式 E、Java的编码方式请用UTF-8或GB2312 F、如果使用STRUTS架构,请加载一个Filter,完成UTF-8或GB2312的转换。 G、tomcat的server.xml中的 打开tomcat的server.xml文件,找到区块,加入如下一行: 完整的应如下: <Connectorport='8080' maxThreads='150' minSpareThreads='25' maxSpareThreads='75' enableLookups='false' redirectPort='8443' acceptCount='100' debug='0' connectionTimeout='20000' disableUploadTimeout='true' URIEncoding='UTF-8'/> H:建议j2ee项目(STRUTS架构)的中文解决: 所有jsp文件<%@ page language="java"pageEncoding="GB2312"%> 以(下源码I)中的过滤器采用GB2312 所有xml文件<?xml version="1.0"encoding="UTF-8"?> 打开tomcat的server.xml文件,找到区块,加入如下一行:URIEncoding='UTF-8',具体见G中描述 I:过滤器源码:过滤器源码(java) package zzsy.news.util;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
public class CharacterEncodingFilterimplements Filter {
privateString encoding="";
publicvoid init(FilterConfig args0) throws ServletException {
//得到配置文件中设置的初始值
this.encoding=args0.getInitParameter("encoding");
}
publicvoid doFilter(ServletRequest agrs0, ServletResponse args1,
FilterChainarg2) throws IOException, ServletException {
//强制转换请求、响应对象的类型
HttpServletRequestreq=(HttpServletRequest)agrs0;
HttpServletResponseres=(HttpServletResponse)args1;
//设置请求响应对象中的字符编码
res.setCharacterEncoding("gbk");
req.setCharacterEncoding("gbk");
// System.out.println("通过字符过滤器");
//跳出过滤器,继续执行请求响应
arg2.doFilter(req,res);
}
publicvoid destroy() {
//TODO Auto-generated method stub
}
}过滤器源码(配置) <filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>zzsy.news.util.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>