filteroflanguage.java~5~

来自「基于mvc的宠物管理系统。servlet+jsp」· JAVA~5~ 代码 · 共 52 行

JAVA~5~
52
字号
package com.richard.dao;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class FilterOfLanguage extends HttpServlet implements Filter {
    private FilterConfig filterConfig;
    protected String encoding = null;

    protected boolean ignore = true;

    //Handle the passed-in FilterConfig
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }

    //Process the request/response pair
    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain filterChain) {
        try {

            if (ignore || (request.getCharacterEncoding() == null)) {
                String encoding = selectEncoding(request);
                if (encoding != null) {
                    System.out.println(encoding);
                    request.setCharacterEncoding(encoding);
                }
                System.out.println("Null");
            }

            filterChain.doFilter(request, response);

        } catch (ServletException sx) {
            filterConfig.getServletContext().log(sx.getMessage());
        } catch (IOException iox) {
            filterConfig.getServletContext().log(iox.getMessage());
        }
    }

    protected String selectEncoding(ServletRequest request) {
        return (this.encoding);
    }

    //Clean up resources
    public void destroy() {
        this.encoding = null;
        this.filterConfig = null;
    }
}

⌨️ 快捷键说明

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