防盗链过滤器

作者: 神坛下的我 | 来源:发表于2018-08-23 11:51 被阅读0次

    UseFilter.java

    @WebFilter("/*")
    public class UseFilter implements Filter{
        //private FilterConfig filterConfig;
        @Override
        public void init(FilterConfig filterConfig) throws ServletException {
            //this.filterConfig = filterConfig;
        }
        
        @Override
        public void doFilter(ServletRequest req, ServletResponse resp,
                FilterChain filterChain) throws IOException, ServletException {
                
                HttpServletRequest request=(HttpServletRequest) req;
                HttpServletResponse response=(HttpServletResponse) resp;
                String imurl = request.getHeader("imurl");//连接的来源地址
                if(imurl==null||!imurl.contains(request.getServerName())){//判断访问来源
                request.getRequestDispatcher("/images/a.PNG").forward(request, response);
                }else {
                    filterChain.doFilter(request, response);
                    request.getRequestDispatcher("index.jsp").forward(request, response);
                }
        }
        
        @Override
            public void destroy() {
                
            }
        
    }
    
    7.PNG 8.PNG

    相关文章

      网友评论

        本文标题:防盗链过滤器

        本文链接:https://www.haomeiwen.com/subject/humpiftx.html