过滤器代码

/**
 * 过滤器(转换字符编码)
 * @author Xucheng
 *
 */
public  class EncodingFilter implements Filter {
{
    
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain)
    {
        try
        {
            request.setCharacterEncoding("utf-8");  //设置请求编码
            chain.doFilter(request, response); // 继续向下传递请求
            
        } catch (UnsupportedEncodingException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ServletException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  
     }

    public void destroy(){}
    public void init(FilterConfig filterConfig) throws ServletException{}

}

 

posted @ 2014-03-30 17:14  _____Sky  阅读(238)  评论(0)    收藏  举报