[java]代码库
package pm_cn.itcast.request;
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 RequestDemo3 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 会带过来 : referer: http://localhost:8080/day11/1.html
String headerValue = request.getHeader("referer");
response.setContentType("text/html;charset=utf-8");
if(headerValue==null|| !headerValue.startsWith("http://localhost:8080")){
// 说明是 盗链 过来的 .
response.getWriter().print("哥们, 你是 盗链 过来的 ...");
}else{
// http://localhost:8080
// 说明 不是 盗链 过来的
response.getWriter().print(" 采访 詹姆斯 ");
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}