防盗链
来源:互联网 发布:淘宝网店怎么关闭 编辑:程序博客网 时间:2024/05/16 23:54
盗链:盗链是指服务提供商自己不提供服务的内容,通过技术手段绕过其它有利益的最终用户界面(如广告),直接在 自己的网站上向最终用户提供其它服务提供商的服务内容,骗取最终用户的浏览和点击率。受益者不提供资源或 提供很少的资源,而真正的服务提供商却得不到任何的收益。
通过http的referer请求头实现防盗链;
package cn.guoqing.request;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;//防盗链:public class RequestDemo6 extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {//通过referer请求头,获取客户机在哪个基础地址上的访问该地址的String referer=request.getHeader("referer");//判断该地址是否为盗链访问if(referer==null||!referer.startsWith("http://localhost:8080")){//重定向response.sendRedirect("/day06/referer.html");//禁止下面的代码执行。return;}String data="zhangsan,lisi wangwu";response.getWriter().write(data);}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doGet(request,response);}}
referer.html 文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>防盗链</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head> <body> 广告!!!!!!!!!!!!!!<br/> <a href="/day06/servlet/RequestDemo6">点击链接</a><br> </body></html>
- 防盗链
- 防盗链
- 防盗链
- 防盗链
- 防盗链
- 防盗链
- 防盗链
- 防盗链
- 防盗链
- 防盗链
- 防盗链
- 防盗链
- 防盗链
- 防盗链
- 防盗链
- 防盗链
- 防盗链
- 防盗链
- squeeze debian添加adobe flash player
- 小记2013杭州邀请赛
- 赫夫曼树
- jsoup和w3c的dom解析问题记录
- 更新eclipe主题
- 防盗链
- Codeforces Round #166 (Div. 2) A题
- jpg 格式举例详解
- hdoj_4463Outlets
- java Remote
- Unable to execute dex: Multiple dex files define Lcom
- hdu 4374 One hundred layer
- ASP.NET AJAX之UpdatePanel 和JQUERY冲突
- ACCESS数据库局域网内实现多机数据共享的方法