|
盗用连接 技术
其实很简单
就是利用response 的 头属性来获取客户端 连接到服务端 连接地址
如果连接过来的非本网页地址 的话! 就直接返回到主页去
package com.renxing.Servlet;
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 indexServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
//盗用连 可以通过 客户端的request 来获取相关的方法 来判断 用户从什么地址连接过来的
//如果非指定地址可以通过 response蹦到主页 重新看正版的
String referer=request.getHeader("referer");
if(referer==null||!referer.startsWith("http://localhost:8080"))
{
response.sendRedirect("/mail/index.jsp");
System.out.println(referer);
return;
}
request.getRequestDispatcher("/servlet/HeadServlet").include(request, response);
request.getRequestDispatcher("/servlet/FootServlet").include(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doGet(request, response);
}
}
请求包含
也就是说 在意个页面中要包含这2个内容
request.getRequestDispatcher("/servlet/HeadServlet").include(request, response);
request.getRequestDispatcher("/servlet/FootServlet").include(request, response);
请求调转 forward
request.getRequestDispatcher("/servlet/HeadServlet").forward(request, response);
request.getRequestDispatcher("/servlet/FootServlet").forward(request, response); |
|