filter

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;
    }

你可能感兴趣的:(cache)