JSP实例教程:防盗链

来源:网络时间:2011-07-05

  index.jsp

  -----------------------------

  <html>
  <head><title>Simple jsp page</title></head>
  <body>Place your content here

  here is index jsp
  get header info
  <a href="a.jsp">a.jsp</a>
  </body>
  </html>

  

  ------------------------------

  a.jsp页面
  通过判断 referer, 判断你从哪里来。

  <html>
  <head><title>Simple jsp page</title></head>
  <body>Place your content here

  here is a. jsp
  get header info
  <%=request.getHeader("Referer")%>
  <%if(null == request.getHeader("Referer") || request.getHeader("Referer").indexOf("yourdomain.com") < 0){%>
  做人要厚道
  <%}else{%>
  合法访问
  <%}%>
  </body>
  </html>

意见反馈
发表评论

最新评论(共1条)

2345市网友

indexOf?用startwith吧

2012-03-26 1

回复@2345网友:

  • 取消