public void doFilter(ServletRequest request, ServletResponse response,

AutoLoginFilterpackage com.itheima.tfy.filter.simple;


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;
//解决全站中文乱码问题
//缺点:只对post有效  没有解决post方式 请求参数的乱码问题
public class CharacterEncodingFilter implements Filter {
     private FilterConfig filterConfig;
public void destroy() {


}


public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
String encoding=filterConfig.getInitParameter("encoding");
if(encoding==null){
encoding="UTF-8";
}
response.setCharacterEncoding(encoding);
response.setContentType("text/html;charset="+encoding);

request.setCharacterEncoding(encoding);
chain.doFilter(request, response);



}


public void init(FilterConfig filterConfig) throws ServletException {
   
this.filterConfig=filterConfig;
}


}

你可能感兴趣的:(public void doFilter(ServletRequest request, ServletResponse response,)