package com.web.filter; 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; import javax.servlet.annotation.WebFilter; import javax.servlet.annotation.WebInitParam; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; @WebFilter public class EncodeFilter extends HttpServlet implements Filter{ /** * 编码格式 */ private static final long serialVersionUID = 1L; String encode; @Override public void init(FilterConfig filterConfig) throws ServletException { encode = filterConfig.getInitParameter("encode"); System.out.println("encode"+encode); } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { System.out.println("===EncodeFilter==="); request.setCharacterEncoding(encode); chain.doFilter(request, response); } }