1 16 17 18 package org.apache.webapp.admin.filters; 19 20 21 import java.io.IOException ; 22 import javax.servlet.Filter ; 23 import javax.servlet.FilterChain ; 24 import javax.servlet.FilterConfig ; 25 import javax.servlet.ServletException ; 26 import javax.servlet.ServletRequest ; 27 import javax.servlet.ServletResponse ; 28 import javax.servlet.UnavailableException ; 29 30 31 59 60 public class SetCharacterEncodingFilter implements Filter { 61 62 63 65 66 70 protected String encoding = null; 71 72 73 77 protected FilterConfig filterConfig = null; 78 79 80 83 protected boolean ignore = true; 84 85 86 88 89 92 public void destroy() { 93 94 this.encoding = null; 95 this.filterConfig = null; 96 97 } 98 99 100 111 public void doFilter(ServletRequest request, ServletResponse response, 112 FilterChain chain) 113 throws IOException , ServletException { 114 115 if (ignore || (request.getCharacterEncoding() == null)) { 117 String encoding = selectEncoding(request); 118 if (encoding != null) 119 request.setCharacterEncoding(encoding); 120 } 121 122 chain.doFilter(request, response); 124 125 } 126 127 128 133 public void init(FilterConfig filterConfig) throws ServletException { 134 135 this.filterConfig = filterConfig; 136 this.encoding = filterConfig.getInitParameter("encoding"); 137 String value = filterConfig.getInitParameter("ignore"); 138 if (value == null) 139 this.ignore = true; 140 else if (value.equalsIgnoreCase("true")) 141 this.ignore = true; 142 else if (value.equalsIgnoreCase("yes")) 143 this.ignore = true; 144 else 145 this.ignore = false; 146 147 } 148 149 150 152 153 165 protected String selectEncoding(ServletRequest request) { 166 167 return (this.encoding); 168 169 } 170 171 172 } 173 | Popular Tags |