java源码
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 Rdome4 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //取得浏览器来自于何方 String referer = request.getHeader("referer"); //取得浏览器访问的URL // String url = request.getRequestURL().toString(); //判段 // if(referer != null && url.equals("http://localhost:8080/day04/index.html")) if(referer!=null && referer.equals("http://localhost:8080/day04/index.html")) { //转发到download.html页面 this.getServletContext().getRequestDispatcher("/download.html").forward(request, response); }else { //转发到ad.html页面 this.getServletContext().getRequestDispatcher("/ad.html").forward(request, response); } }}
访问页面:
<!DOCTYPE html><html> <head> <title>index.html</title> <meta name="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head> <body> <a href="/day04/Rdome4">进入下载页面</a> </body></html>
成功后跳转下载页面
<!DOCTYPE html><html> <head> <title>download.html</title> <meta name="keywords" content="keyword1,keyword2,keyword3"> <meta name="description" content="this is my page"> <meta name="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head> <body> 这是下载页面<br> </body></html>
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦