- public class RequestPreventThreif extends HttpServlet {
- private static final long serialVersionUID = 1L;
- //防盗链:用于保护自己独有的消息,防止被其他的网站直接连接浏览,利于保护自己的信息
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- String referer=request.getHeader("referer");
- if(referer==null||!referer.startsWith("http://localhost"))
- {
- response.sendRedirect("/Request/Index.html");
- return; //这个return很重要,如果是盗链那就返回,后续的代码不执行了,也看不到下面的data数据
- }
- String data="haha";
- response.getWriter().write(data);
- }
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- doGet(request,response);
- }
- }
java 防盗链
最新推荐文章于 2021-02-20 00:15:12 发布