在struts1.2中,往数据库插入数据出现中文乱码

来源:百度知道 编辑:UC知道 时间:2024/05/24 06:02:39
在struts1.2中,在dao层往数据库插入中文的时候,数据库出现乱码,我在action中,request.set编码("gb2312")还是不行,怎么解决?

那就写个编码过滤器了
package com.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;

public class Encoding implements Filter {
@SuppressWarnings("unused")
private FilterConfig config=null;
String encoding=null;
public void destroy() {
this.encoding=null;
this.config=null;

}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if(encoding!=null)
request.setCharacterEncoding(encoding);
chain.doFilter(request, response);

}

public void init(FilterConfig arg0) throws ServletException {
this.config=arg0;
this.encoding=ar