简单的防盗链技术(过滤器原理)
Posted liclblog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单的防盗链技术(过滤器原理)相关的知识,希望对你有一定的参考价值。
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() {
}
}
简单的防盗图片过滤器代码
以上是关于简单的防盗链技术(过滤器原理)的主要内容,如果未能解决你的问题,请参考以下文章