Filter过滤器

本文阅读 1 分钟
首页 代码,Java 正文

img

img

img 案例:

package com.jkj.web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
@WebFilter("/*")
public class FilterTest implements Filter { 


    @Override
    public void init(FilterConfig filterConfig) throws ServletException { 

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { 
        //放行前
        System.out.println("1.FilterTest...");
        //放行
        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println("5.FilterTest...");
    }

    @Override
    public void destroy() { 

    }
}
/* 1.FilterTest... 2.Hello JSP! 3.FilterTest... */


package com.jkj.web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter("/*")
public class FilterTest1 implements Filter { 
    @Override
    public void init(FilterConfig filterConfig) throws ServletException { 

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { 
        //放行前
        System.out.println("2.FilterDemo...");
        //放行
        filterChain.doFilter(servletRequest, servletResponse);
        //放行后
        System.out.println("4.FilterDemo...");

    }

    @Override
    public void destroy() { 

    }
}
/* 1.FilterTest... 2.FilterDemo... 3.Hello JSP! 4.FilterDemo... 5.FilterTest... */
本文为互联网自动采集或经作者授权后发布,本文观点不代表立场,若侵权下架请联系我们删帖处理!文章出自:https://blog.csdn.net/qq_43514330/article/details/125336493
-- 展开阅读全文 --
安全面试之XSS(跨站脚本攻击)
« 上一篇 07-24

发表评论

成为第一个评论的人

热门文章

标签TAG

最近回复