日期:2014-05-18  浏览次数:20670 次

linu as4.0 下 mysql数据库插入时乱码问题!!!求高人解决!!!
我的系统是linu   as4.0+tomcat5.5+jdk1.5数据库是mysql5.0.27
现在向数据库中插入汉字的时候是乱码...
以前用的是red9.0是可以的但是换到linu   as4.0时插入数据的时候,汉字就是乱码了,提取曾经在red9.0下添加的汉字是好的没有出现乱码。
在网上说改变/etc/mysql/my.cnf
my.cnf这个文件,但是改了也没有用阿!该怎么办呢?

------解决方案--------------------
在安装mysql初期的就要在设置里面把字符 设置成utf8(具体的随便你)
在页面里面
<%@ page contentType= "text/html; charset=UTF-8 "%>
<meta http-equiv= "Content-Type " content= "text/html; charset=UTF-8 " />

设置过滤器
package com.struts.filter;

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;

public class SetCharacterEncodingFilter implements Filter {
protected String encoding = null;

protected FilterConfig filterConfig = null;

protected boolean ignore = true;

public void destroy() {
this.encoding = null;
this.filterConfig = null;
}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {

// Conditionally select and set the character encoding to be used
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null) {
request.setCharacterEncoding(encoding);
}
}

// Pass control on to the next filter
chain.doFilter(request, response);

}

public void init(FilterConfig filterConfig) throws ServletException {

this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter( "encoding ");
String value = filterConfig.getInitParameter( "ignore ");
if (value == null) {
this.ignore = true;
} else if (value.equalsIgnoreCase( "true ")) {
this.ignore = true;
} else if (value.equalsIgnoreCase( "yes ")) {
this.ignore = true;
} else {
this.ignore = false;
}

}

protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}

}
web.xml上设置
<filter>
<filter-name> setCharacterEncodingFilter </filter-name>
<filter-class> com.accp.filter.SetCharacterEncodingFilter </filter-class>
<init-param>
<param-name> encoding </param-name>
<param-value> UTF-8 </param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name> setCharacterEncodingFilter </filter-name>
<url-pattern> /* </url-pattern>
</filter-mapping>