HTTP 헤더에 보면, Referer라는 헤더가 존재한다. 이는 브라우져가 가지고 있다가 요청시 사용하게 된다.

예를 들어 어느 웹서버로부터 우리 서버가 노출되고 있는지 알고 싶을 때, 또는 쇼핑 서버로부터 연동하는 웹서버의 경우 유용하게 써먹어 볼 수 있다.

 

(HttpServeltRequest request)

String ref = request.getHeader("referer");

if ("google".indexOf(ref)) {

    // DB 저장.

}

 

 

 

javax.servlet.http
Interface HttpServletRequest

 

getHeader

public java.lang.String getHeader(java.lang.String name)
Returns the value of the specified request header as a String. If the request did not include a header of the specified name, this method returns null. The header name is case insensitive. You can use this method with any request header.
Parameters:
name - a String specifying the header name
Returns:
a String containing the value of the requested header, or null if the request does not have a header of that name

 

Posted by '김용환'
,