encodingfilter.java

来自「java swing源码 欢迎下载 有问题请联系 我一定负责到底」· Java 代码 · 共 55 行

JAVA
55
字号
package com.sinosoft.common;

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.UnavailableException;

/**
 * <p>Title: 中文问题</p>
 * <p>Description: 中文问题</p>
 * <p>Copyright: Copyright (c) 2002 writeonce</p>
 * <p>Company: </p>
 * @author writeonce
 * @version 1.0
 */

public class EncodingFilter implements Filter {
    protected String encoding = null;
    protected FilterConfig filterConfig = null;
    public void destroy() {
        this.encoding = null;
        this.filterConfig = null;

    }
    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain)
throws IOException, ServletException {
        // Select and set (if needed) the character encoding to be used
        String encoding = selectEncoding(request);
        if (encoding != null)
        {
            request.setCharacterEncoding(encoding);
        }
// Pass control on to the next filter
        chain.doFilter(request, response);
    }
    public void init(FilterConfig filterConfig) throws ServletException {

this.filterConfig = filterConfig;
        this.encoding = filterConfig.getInitParameter("encoding");
    }
    protected String selectEncoding(ServletRequest request) {

        return (this.encoding);

    }


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?