1 18 19 package cowsultants.itracker.web.filters; 20 21 import java.io.IOException ; 22 import javax.servlet.*; 23 24 29 public class SetRequestCharacterEncoding implements Filter { 30 public static final String DEFAULT_ENCODING = "UTF-8"; 31 32 private FilterConfig filterConfig = null; 33 private String encoding = null; 34 35 43 public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException , ServletException { 44 request.setCharacterEncoding(getEncoding()); 45 filterChain.doFilter(request, response); 46 } 47 48 52 public void init(FilterConfig filterConfig) throws ServletException { 53 this.filterConfig = filterConfig; 54 setEncoding(filterConfig.getInitParameter("encoding")); 55 } 56 57 60 public String getEncoding() { 61 return (encoding == null ? DEFAULT_ENCODING : encoding); 62 } 63 64 67 public void setEncoding(String value) { 68 if(value != null) { 69 encoding = value; 70 } 71 } 72 73 76 public void destroy() { 77 encoding = null; 78 filterConfig = null; 79 } 80 } 81 82 | Popular Tags |