过滤器

public class

public class EncodingChange implements Filter  {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected FilterConfig filterConfig = null; 
	protected String encoding = ""; 
	public void destroy() {
		filterConfig = null; 
		encoding = null; 
	}
	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
			throws IOException, ServletException {
		if(encoding != null) 
			
			servletRequest.setCharacterEncoding(encoding); 
			System.out.println("请求参数的编码变为:"+encoding);
			filterChain.doFilter(servletRequest, servletResponse); 
	}
	public void init(FilterConfig filterConfig) throws ServletException {
		this.filterConfig = filterConfig; 
		this.encoding = filterConfig.getInitParameter("encoding"); 
		System.out.println("web.xml配置的编码是"+encoding);
	}
}

 

你可能感兴趣的:(过滤器)