1 23 24 86 package org.dbforms.util.external; 87 88 import java.io.IOException ; 89 90 import javax.servlet.Filter ; 91 import javax.servlet.FilterChain ; 92 import javax.servlet.FilterConfig ; 93 import javax.servlet.ServletException ; 94 import javax.servlet.ServletRequest ; 95 import javax.servlet.ServletResponse ; 96 97 98 99 136 public class SetCharacterEncodingFilter implements Filter { 137 141 protected FilterConfig filterConfig = null; 142 143 145 149 protected String encoding = null; 150 151 152 protected boolean ignore = true; 153 154 156 159 public void destroy() { 160 this.encoding = null; 161 this.filterConfig = null; 162 } 163 164 165 176 public void doFilter(ServletRequest request, 177 ServletResponse response, 178 FilterChain chain) 179 throws IOException , ServletException { 180 if (ignore || (request.getCharacterEncoding() == null)) { 182 String pencoding = selectEncoding(request); 183 184 if (pencoding != null) { 185 request.setCharacterEncoding(pencoding); 186 } 187 } 188 189 chain.doFilter(request, response); 191 } 192 193 194 199 public void init(FilterConfig afilterConfig) throws ServletException { 200 this.filterConfig = afilterConfig; 201 this.encoding = filterConfig.getInitParameter("encoding"); 202 203 String value = filterConfig.getInitParameter("ignore"); 204 205 if (value == null) { 206 this.ignore = true; 207 } else if (value.equalsIgnoreCase("true")) { 208 this.ignore = true; 209 } else if (value.equalsIgnoreCase("yes")) { 210 this.ignore = true; 211 } else { 212 this.ignore = false; 213 } 214 } 215 216 217 219 235 protected String selectEncoding(ServletRequest request) { 236 return (this.encoding); 237 } 238 } 239 | Popular Tags |