所谓的防盗链就是当你以一个非正常渠道去访问某一个Web资源的时候,服务器会将你的请求忽略并且将你的当前请求变为按正常渠道访问时的请求并返回到相应的页面,用户只有通过该页面中的相关操作去访问想要请求的最终资源。
例如:你想访问url1:https://www.hao123.com,如果url1做了防盗链处理,即url1只允许通过合法的链接进入,例如url2:https://www.baidu.com/,当直接输入url1时,会先跳转到url2,通过点击url2页面的“hao123”按钮,才能正常访问url1,这就是防盗链技术。
例如:
public class Request extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {getDoorChain(request, response);}
private void getDoorChain(HttpServletRequest request,
HttpServletResponse response) throws IOException {
//通过request获取请求头参数
String referer = request.getHeader("referer");
if(referer==null || !referer.endsWith("http://localhost:8080/Request/index.jsp")){
response.sendRedirect("http://localhost:8080/Request/index.jsp");
return;
}
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset =utf-8");
PrintWriter pw = response.getWriter();
pw.write("喜剧片《东成西就》");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
<body>
这里是防盗链技术的应用检测! <br>
<a href ="/Request/Request" >喜剧片 </a>
</body>
</html>
通过http://lcoalhost:8080/Request/Request这个网址获取到我想要的《东成西就》
的资源可是当我真正的输入这个网址时,却转到了:
http://localhost:8080/Request/index.jsp这个页面
1459

被折叠的 条评论
为什么被折叠?



