插入数据库为乱码,怎么解决

YUNYUN_033 2007-05-13 08:12:25
...全文
123 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
javaboy2006 2007-05-13
  • 打赏
  • 举报
回复
搞个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;

public void init(FilterConfig arg0) throws ServletException {
this.filterConfig = arg0;
this.encoding = "GBK"
}

public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
if (arg0.getCharacterEncoding() == null) {
arg0.setCharacterEncoding(this.encoding);
}

arg1.setContentType("text/html; charset=" + this.encoding);
arg2.doFilter(arg0, arg1);
}

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


jk88811 2007-05-13
  • 打赏
  • 举报
回复
两点

统一编码

使用Filter

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧