package com.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.servlet.*;
import java.io.IOException;
public class EncodingFilter implements Filter {
private Log log = LogFactory.getLog(getClass());
private String encoding = "UTF-8";
public void destroy() {
log.info("EncodingFilter destroyed.");
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding(encoding);
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException {
String encoding = filterConfig.getInitParameter("encoding");
if (encoding != null && !"".equals(encoding.trim()))
this.encoding = encoding.trim();
log.info("Request character encoding is set to " + encoding);
}
}