File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes getHeader( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "getHeader("Referer") returns null" Watch "getHeader("Referer") returns null" New topic

getHeader("Referer") returns null

Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1868
Any one has any idea as to why the request.getHeader(Referer) info is lost when a page is opened in a new window.
It works fine when opened in the same window.
---HTML PAGE-----
<script language="Javascript">

function windowOpener(url,width,height,name,scrolls)
browserName = navigator.appName;
browserVer = navigator.appVersion.substring(0,1);
if (width==null) {width=417;}
if (height==null) {height=470;}
if (name==null) {name="globaltPopup";}
if (scrolls==true) {
else {
if (browserName != "Netscape" || browserVer != 2)
+ scrollsOption + ",resizable=no");
} = "9kZF4Fw8lOLitrXrl9rcj3wbNLs2jg1qzrJsSIn2V078rOf5gjB4!1521296358!170405968!7501!7502";
<a href="javascript:windowOpener('http://localhost:7501/w/c/n', 417, 470,'note',true);">localhost new window </a>
<a href="http://localhost:7501/w/c/n">localhost new window </a>

<% String referer=request.getHeader("Referer");
System.out.println("domain 1 is :"+domain+":");
System.out.println("referer is :"+referer+":");
out.println("Request headers:");
Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
System.out.println("IN HEADER NAMES");
String name = (String) headerNames.nextElement();
System.out.println("IN HEADER NAMES :"+name);
String value = request.getHeader(name);
System.out.println("IN HEADER NAMES :"+value);
if(referer!=null && referer.indexOf("")!=-1){%>
if (window.opener)
window.opener.location = '<%=domain%>';
In the new window cases the referer header is null
But when opened in the same window the referer contains a vaild URL.
Any ideas
I agree. Here's the link:
subject: getHeader("Referer") returns null
It's not a secret anymore!