码迷,mamicode.com
首页 > 其他好文 > 详细

简单的防盗链技术(过滤器原理)

时间:2018-08-04 21:01:22      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:out   ini   图片   null   ref   img   https   str   request   

public class ImgFilter implements Filter {

public void init(FilterConfig filterConfig) throws ServletException {
System.out.println("过滤器初始化...");
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
System.out.println("doFilter...");

HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
String referer = req.getHeader("referer");
// 请求服务名称 
String serverName = req.getServerName();
System.out.println("referer:" + referer + ",serverName:" + serverName);
if (referer == null || !(referer.contains(serverName))) {
//
req.getRequestDispatcher("error.png").forward(req, res);
return ;
}

//放行
chain.doFilter(req, res);
}

public void destroy() {

}

}

 

简单的防盗图片过滤器代码

简单的防盗链技术(过滤器原理)

标签:out   ini   图片   null   ref   img   https   str   request   

原文地址:https://www.cnblogs.com/liclBlog/p/9419865.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!