我的系统是linu as4.0+tomcat5.5+jdk1.5数据库是mysql5.0.27
现在向数据库中插入汉字的时候是乱码...
以前用的是red9.0是可以的但是换到linu as4.0时插入数据的时候,汉字就是乱码了,提取曾经在red9.0下添加的汉字是好的没有出现乱码。
在网上说改变/etc/mysql/my.cnf
my.cnf这个文件,但是改了也没有用阿!该怎么办呢?
现在向数据库中插入汉字的时候是乱码...
以前用的是red9.0是可以的但是换到linu as4.0时插入数据的时候,汉字就是乱码了,提取曾经在red9.0下添加的汉字是好的没有出现乱码。
在网上说改变/etc/mysql/my.cnf
my.cnf这个文件,但是改了也没有用阿!该怎么办呢?
解决方案 »
- 能给菜鸟一点建议吗?各位前辈们。。没事就来踩下帖吧,看看也好
- 上传多个图片,且转换为二进制流怎么弄.
- 跑求TOMCAT问题
- tomcat 5.5+jdk1.5_06怎么配置?
- 请推荐几个适合初学者学习的例子?
- 用javamail收取附件,在取得附件内容时,是不是必须将附件保存到磁盘才能提供下载?这样不是不安全了吗?另外保存到磁盘的文件如果要自动
- 请问如何做一个类似csdn中输入关键字,而后在本网站内容中进行搜索的引擎?
- 如何在java里面调用vc写的.dll动态库??(高手帮忙,绝对高分相赠,)
- 为什么没有结果啊???请哪位高手帮忙看看,在线等待,解决马上结帐!!!!!!!
- 字符串问题
- 小问题,有空的人帮我这个菜鸟下
- 谢谢大家!
在页面里面
<%@ 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>
原来是系统字符集要改一下
以前是zh gb18030
把现在的改成以前的就好啦
不过你的方法我会好好保留的
谢谢阿