锁链接
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <a href="/WEB06/HeadServlet">神州十二号</a> </body> </html>
package com.oracle.demo01; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class HeadServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 获取referer头 // 就是获取链接 String referer=request.getHeader("Referer"); // 解决乱码 response.setContentType("text/html;charset=UTF-8"); // 判断是不是本地服务期(是不是这个格式) if(referer.startsWith("http://localhost")){ response.getWriter().write("中国航院七次问天"); }else{ response.getWriter().write("你是小偷"); } } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }