代码巨简单,jsp的就不用说了,过滤器是这样
public class CharsetFilter implements Filter{
private FilterConfig config = null;
private String defaultEncode = "UTF-8";
public void init(FilterConfig config) throws ServletException {
this.config = config;
}
public void destroy() {
this.config = null;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
System.out.println("into filter");
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// response.setCharacterEncoding("gbk");
chain.doFilter(request,response);
}
}
jsp 页面都是UTF-8编码的,eclipse的项目编码也是UTF-8 的,谢谢