编码过滤器

 

package com.pynon.webapp.action;



import java.io.IOException;
import javax.servlet.*;


public class EncodingFilter implements Filter {

	protected String encoding = null;
	protected FilterConfig config;

	public void init(FilterConfig filterConfig) throws ServletException {
		this.config = filterConfig;

		
		this.encoding = filterConfig.getInitParameter("Encoding");
	}

	public void doFilter(
		ServletRequest request,
		ServletResponse response,
		FilterChain chain)
		throws IOException, ServletException {
		if (request.getCharacterEncoding() == null) {			
		
			String encode = getEncoding();
			if (encode != null) {				
				
				request.setCharacterEncoding(encode);
			}
		}
		chain.doFilter(request, response);
	}

	protected String getEncoding() {
		return encoding;
	}

	public void destroy() {

	}

}

 


你可能感兴趣的:(servlet)