标签:发送 return dispatch 二进制 row response image == gets
防盗链:
@WebFilter(filterName = "imgFilter",value = "/img/*") public class MckzFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { System.out.println("过滤器开始"); } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { System.out.println("梅川酷子"); //获取上一个请求地址 HttpServletRequest httprequest=(HttpServletRequest)request; HttpServletResponse httpresponse=(HttpServletResponse)response; //获取上一个请求地址 String referer = httprequest.getHeader("Referer"); //获取本项目的请求地址 String serverName = httprequest.getServerName(); System.out.println(referer+"\t"+serverName); //判断 //如果上一个请求地址为空或者非本项目的请求地址拦截 if(referer==null||!referer.contains(serverName)){ request.getRequestDispatcher("/img/asd.jpg").forward(request,response); return; } chain.doFilter(request,response); } @Override public void destroy() { System.out.println("过滤器关闭"); } }
标签:发送 return dispatch 二进制 row response image == gets
原文地址:https://www.cnblogs.com/whtt/p/12259511.html