使用Referer實現防盜鏈防下載2

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		HttpServletRequest req = (HttpServletRequest) request;
		HttpServletResponse res = (HttpServletResponse) response;
		//獲取連接
		String referer=req.getHeader("referer");
		System.out.println(referer);
		int duankou=request.getLocalPort();
		//獲取本電腦ip地址
		String serverName=req.getServerName();
		String ip="http://"+serverName+":"+duankou+"/";
		if(referer==null||!referer.contains(serverName)||referer.contains("jiump4")||referer.equals(ip)){
			req.getRequestDispatcher("/images/timg.jpg").forward(req, res);
			return;
		}
		chain.doFilter(req, res);
		
		
	}
<filter>
 	<filter-name>RefererFilter</filter-name>
 	<filter-class>com.enet.fileter.RefererFilter</filter-class>
 </filter>
 <filter-mapping>
 	<filter-name>RefererFilter</filter-name>
 	<url-pattern>/jiump4/*</url-pattern>
 </filter-mapping>

 

在上個版本發現了一點問題app

referer中在下載的時候,獲取到的地址 資源的地址 or http:// +ip地址+ : +端口號+ / url

 

而後我修改了一下判斷spa

相關文章
相關標籤/搜索