1 16 package dlog4j; 17 18 import java.io.IOException ; 19 20 import javax.servlet.Filter ; 21 import javax.servlet.FilterChain ; 22 import javax.servlet.FilterConfig ; 23 import javax.servlet.ServletException ; 24 import javax.servlet.ServletRequest ; 25 import javax.servlet.ServletResponse ; 26 import javax.servlet.http.HttpServletResponse ; 27 28 import dlog4j.proxy.ResponseProxy; 29 30 36 public class ContentTypeFilter implements Filter { 37 38 protected String contentType = "text/html;charset=UTF-8"; 39 40 public void init(FilterConfig config) throws ServletException { 41 String ct = config.getInitParameter("contentType"); 42 if(ct!=null && ct.trim().length()>0) 43 contentType = ct; 44 } 45 46 49 public void doFilter(ServletRequest req, ServletResponse res, 50 FilterChain chain) throws IOException , ServletException { 51 res.setContentType(contentType); 52 HttpServletResponse p_res = ResponseProxy.getProxy(res).getInstance(); 53 chain.doFilter(req, p_res); 54 } 55 56 59 public void destroy() { 60 } 61 62 } 63 | Popular Tags |