javaweb视频referer防盗链


附加 java源码包下载地址

package cn.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

/*
 * 参数拦截器
 * */
public class Mp4Filter implements Filter {

	public void destroy() {
	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request1=(HttpServletRequest) request;
		if(request1.getHeader("referer").equals("???")){//这里的?指的是你要从哪个url src视频,比如我在www.baidu.com写了video src这个视频这边???就要写www.baidu.com,如果不等于它就会禁止。
			chain.doFilter(request1, response);
		}
		else{

		}
	}

	public void init(FilterConfig fConfig) throws ServletException {
	}
}

然后在web.xml配置


		Mp4filter
		cn.filter.Mp4Filter
	
	
		Mp4filter
		*.mp4
	

你可能感兴趣的:(javaweb视频referer防盗链)