Plus
Import javax.servlet. *; import java.io.ioException;
Public class setcharacterencodingfilter imports filter {
/ / -------------------------------------------------------------------------------------------- ----- Instance Variables
/ ** * The default character Encoding to set for reviews That pass * this filter. * / Protected string encoding = null;
/ ** * The filter configuration Object We are associated with. If this value * is null, this filter instance is not currently configured. * / Protected filterconfig filterfig = null;
/ ** * SHOULD a Character Encoding Specified by the client be ignored? * / Protected boolean ignore = true;
/ / -------------------------------------------------------------------------------------------- --------- Public Methods
/ ** * Take this filter out of service. * / Public void destroy () {
THIS.Encoding = null; this.filterconfig = NULL;
}
/ ** * Select and set (if specified) the character encoding to be used to * interpret request parameters for this request. * * @Param request The servlet request we are processing * @param result The servlet response we are creating * @param chain The filter chain we are processing * * @exception IOException if an input / output error occurs * @exception ServletException if a servlet error occurs * / public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {// conditionally select and set the character encoding to be used if (ignore || (request.getCharacterEncoding () == null)) {String encoding = selectEncoding (request); if (! encoding = null) request.setCharacterEncoding (encoding);}
// Pass Control on to the next filter chain.dofilter (request, response);
}
/ ** * Place this filter into service. * * @Param FilterConfig the filter configuration Object * / public void init (filterconfig filterconfig) throws servletexception {
this.filterConfig = filterConfig; this.encoding = filterConfig.getInitParameter ( "encoding"); String value = filterConfig.getInitParameter ( "ignore"); if (value == null) this.ignore = true; else if (value.equalsIgnoreCase ("True")) this.Ignore = true; Else IF (Value.Equalsignorecase ("YES")) this.Ignore = true; else this.ignore = false;
}
/ / -------------------------------------------------------------------------------------------- ------ Protected Methods / ** * Select an appropriate character encoding to be used, based on the * characteristics of the current request and / or filter initialization * parameters. If no character encoding should be set, return * * The default implementation unconditionally returns the value configured * by the encoding strong> initialization parameter for this * filter. * * @param request The servlet request we are processing * / Protected string selectencoding (servletRequest request) { Return (this.encoding); } } null code>. *