java WEB Refer 도 난 방지 체인 실례 화 코드

945 단어 web
package cn.com;

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 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;
		}
		String data="haha";
		response.getWriter().write(data);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}

좋은 웹페이지 즐겨찾기