package com.ag.secp.platform.filter;


import javax.servlet.*;
import java.io.IOException;

public class EncodingFilter implements Filter{

    private String targetEncoding = "UTF-8";
    private FilterConfig filterConfig = null;

    public void init(FilterConfig filterConfig) throws ServletException {
        //获取配置文件
        this.filterConfig = filterConfig;
        //获取配置文件中的编码信息
        this.targetEncoding = this.filterConfig.getInitParameter("encoding");
    }

    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain filterChain) throws IOException, ServletException {
        request.setCharacterEncoding(this.targetEncoding);
        filterChain.doFilter(request, response);
    }

    public void destroy() {
        this.filterConfig = null ;
        this.targetEncoding = null ;
    }
}