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; // solves Chinese garbled characters throughout the site // disadvantage: it is only valid for post and does not solve the garbled problem of post Request Parameters. 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 ;}}