一.防盗链
在页面中请求不属于自己的资源, 可以增加自己的流量, 耗费别人的宽带.
Demo: 防止倒链(使用过滤器)
@WebFilter(urlPatterns="/img/*") public class ChainFilter implements Filter { @Override public void destroy() { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { //向下转型 HttpServletRequest req = (HttpServletRequest)request; HttpServletResponse resp = (HttpServletResponse)response; String str = req.getHeader("referer"); System.out.println(str); if (str.contains("sxtpms")) { chain.doFilter(req, resp); } else { resp.getWriter().println("不可以盗链!"); } } @Override public void init(FilterConfig filterConfig) throws ServletException { } }