关于 referer

在开发web程序的时候,有时我们需要得到用户是从什么页面链接过来的,这就用到了referer。

它是http协议,所以任何能开发web程序的语言都可以实现.


比如jsp中是:
request.getHeader("referer");
php是:
$_SERVER['HTTP_REFERER']。

Referer 获取来访者地址。只有通过链接访问当前页的时候,才能获取上一页的地址;否则request.getHeader("Referer")的值为Null,通过window.open打开当前页或者直接输入地址,也为Null。

HttpServletRequest.getHeader

String getHeader(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. If there are multiple headers with the same name, this method returns the first head in the request. 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
 

HttpServletRequest.getHeaders

Enumeration getHeaders(String name)
Returns all the values of the specified request header as an Enumeration of String objects.

Some headers, such as Accept-Language can be sent by clients as several headers each with a different value rather than sending the header as a comma separated list.

If the request did not include any headers of the specified name, this method returns an empty Enumeration. The header name is case insensitive. You can use this method with any request header.

Parameters:
name - a String specifying the header name
Returns:
an Enumeration containing the values of the requested header. If the request does not have any headers of that name return an empty enumeration. If the container does not allow access to header information, return null

猜你喜欢

转载自huangqiqing123.iteye.com/blog/2002216