编码工具类

package com.web.filter;

import java.io.IOException;

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.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@WebFilter
public class EncodeFilter extends HttpServlet implements Filter{

    /**
     * 编码格式
     */
    private static final long serialVersionUID = 1L;
    String encode;
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    
        encode = filterConfig.getInitParameter("encode");
        System.out.println("encode"+encode);
    }
        
    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {        
        System.out.println("===EncodeFilter===");            
        request.setCharacterEncoding(encode);        

        chain.doFilter(request, response);
    }
}

 

posted @ 2017-11-24 17:53  沉默不会很久  阅读(186)  评论(0编辑  收藏  举报