zoukankan      html  css  js  c++  java
  • 011-filter模板

    1 模板一

    package ${enclosing_package};
    
    import java.io.IOException;
    
    import javax.servlet.FilterChain;
    
    import javax.servlet.FilterConfig;
    
    import javax.servlet.ServletException;
    
    import javax.servlet.ServletRequest;
    
    import javax.servlet.ServletResponse;
    
    import javax.servlet.Filter;
    
    import javax.servlet.http.HttpServletRequest;
    
    import javax.servlet.http.HttpServletResponse;
    
    import javax.servlet.http.HttpSession;
    
    public class ${primary_type_name} implements Filter{
    
        public ${primary_type_name}(){
            super();
        }
        private FilterConfig filterConfig;
    
        public void init(FilterConfig filterConfig) throws ServletException{
    
            this.filterConfig = filterConfig;
    
        }
    
        public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain){
    
            try{
    
                HttpServletRequest request = (HttpServletRequest) req;
    
                HttpServletResponse response = (HttpServletResponse) res;
    
                HttpSession session = request.getSession();
    
                // 这里放到达目的地前(进入)处理代码   
    
                filterChain.doFilter(req, res);
    
                // 这里放到达目的地(离开)的处理代码   
    
            } catch (IOException e){
    
                e.printStackTrace();
    
            } catch (ServletException e){
    
                e.printStackTrace();
            }
    
        }
    
        public void destroy(){
    
        }
    }

    2 模板二

    package ${enclosing_package};
    
    import java.io.IOException;
    
    import javax.servlet.FilterChain;
    
    import javax.servlet.FilterConfig;
    
    import javax.servlet.ServletException;
    
    import javax.servlet.ServletRequest;
    
    import javax.servlet.ServletResponse;
    
    import javax.servlet.Filter;
    
    import javax.servlet.http.HttpServletRequest;
    
    import javax.servlet.http.HttpServletResponse;
    
    import javax.servlet.http.HttpSession;
    
    public class ${primary_type_name} implements Filter {
    
        public ${primary_type_name}() {
            super();
        }
        private FilterConfig filterConfig;
    
        public void init(FilterConfig filterConfig) throws ServletException {
    
            this.filterConfig = filterConfig;
    
        }
        public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException {
    
                HttpServletRequest request = (HttpServletRequest) req;
    
                HttpServletResponse response = (HttpServletResponse) res;
    
                HttpSession session = request.getSession();
    
                // 这里放到达目的地前(进入)处理代码   
    
                filterChain.doFilter(req, res);
    
                // 这里放到达目的地(离开)的处理代码   
        }
    
        public void destroy() {
    
        }
    }
  • 相关阅读:
    查看full gc频率怎么样
    【LeetCode每天一题】Linked List Cycle II(循环链表II)
    【LeetCode每天一题】Word Break()
    【LeetCode每天一题】Candy(分糖果)
    【LeetCode每天一题】Single Number II(数组中单个数字II)
    【LeetCode每天一题】Gas Station(汽油站)
    【LeetCode每天一题】Single Number(数组中单独的数字)
    【LeetCode每天一题】Sum Root to Leaf Numbers(二叉树所有根到叶节点之和)
    【LeetCode每天一题】Longest Consecutive Sequence(最长的连续序列
    【LeetCode每天一题】 Word Ladder(单词阶梯)
  • 原文地址:https://www.cnblogs.com/jepson6669/p/8406511.html
Copyright © 2011-2022 走看看