shop9\src\com\itcast\web\filter

SetCodeFilter.java


package com.itcast.web.filter;

import java.io.IOException;
import java.util.Date;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.ConvertUtils;

import com.itcast.bean.privilege.SystemPrivilegePK;
import com.itcast.bean.product.Sex;
import com.itcast.utils.DateConverter;
import com.itcast.utils.SexConverter;
import com.itcast.utils.SystemPrivilegePKConverter;

public class SetCodeFilter implements Filter {

	public void destroy() {}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain filterchain) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) request;
		req.setCharacterEncoding("UTF-8");
		filterchain.doFilter(request, response);
	}

	public void init(FilterConfig arg0) throws ServletException {
		ConvertUtils.register(new DateConverter(), Date.class);
		ConvertUtils.register(new SexConverter(), Sex.class);
		ConvertUtils.register(new SystemPrivilegePKConverter(), SystemPrivilegePK.class);
	}

}

你可能感兴趣的:(java,apache,Web,bean,servlet)