在struts1.2中,往数据库插入数据出现中文乱码
来源:百度知道 编辑:UC知道 时间:2024/05/24 06:02:39
那就写个编码过滤器了
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