You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "John M. Corro" <jo...@cornerstone.net> on 2002/03/13 16:11:06 UTC

Best way to find referrer

I'm looking to find the best way to find the referring page (ie find out where the user came from).  So far this is the piece of code I have...

Enumeration e = request.getHeaderNames();
String refText = null;

while (e.hasMoreElements())
{
    String key = (String)e.nextElement();
    if (key.equals("referer"))
    {
        refText = request.getHeader(key);
        break;
    }
}

I have to imagine that there's a better way to do this..does anyone have any insight?  I checked google and the servlet javadocs and didn't see anything that simplified this code.  Otherwise, I'll just drop this piece of code into a util class.  Just seeing if I'm reinventing the wheel.  Thanks.