public class CharacterEncodingFilter implements Filter {
private FilterConfig filterConfig;
private String enable;
private String encoding;
public CharacterEncodingFilter() {
filterConfig = null;
enable = null;
encoding = null;
}
public void destroy() {
filterConfig = null;
enable = null;
encoding = null;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) throws IOException, ServletException {
if (enable.equals(SystemParam.PARA_ENABLE_VALUE_FALSE)) {
filterChain.doFilter(request, response);
return;
} else {
request.setCharacterEncoding(encoding);
filterChain.doFilter(request, response);
return;
}
}
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
enable = this.filterConfig.getInitParameter(SystemParam.PARA_ENABLE_NAME);
if (enable == null) {
enable = SystemParam.PARA_ENABLE_VALUE_TRUE;
}
encoding = this.filterConfig.getInitParameter(SystemParam.PARA_ENCODING_NAME);
}
}
拿分。