---
title: "filter"
author: "mintelong"
date: "2010-10-27T16:36:34Z"
tags: []
categories: ["Web前端"]
slug: "filter"
draft: false
lastmod: "2010-10-27T16:36:34Z"
id: 795692
url: "https://mintelong.iteye.com/blog/795692"
---

private FilterConfig filterConfig;

    public SetCharacterEncodingFilter()  
    {  
    }

    public void destroy()  
    {  
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)  
        throws IOException, ServletException  
    {  
        try  
        {  
            request.setCharacterEncoding("UTF-8"); //GB2312 UTF-8  
            HttpServletResponse res = (HttpServletResponse)response;  
           /* res.setHeader("Pragma", "No-cache");  
            res.setHeader("Cache-Control", "no-cache");  
            res.setHeader("Pragram", "no-cache");\*/  
            res.setCharacterEncoding("UTF-8");  
            filterChain.doFilter(request, response);  
        }  
        catch(ServletException e)  
        {  
            filterConfig.getServletContext().log(e.getMessage());  
        }  
        catch(IOException e)  
        {  
            filterConfig.getServletContext().log(e.getMessage());  
        }  
    }

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