Java/JSP - Access to Previous URL

September 28, 2009 at 07:47:57
Specs: Linux
Hi, having trawled the net, I cant find an absolute answer, so am hoping you can help.

I am building a corporate web site that has a variable strap line / message on the home page. At the moment the message is randomly generated and may not therefore relate to what a visitor is interested in.

What I want to do is examine the URL of the referring page to see if there are any clues as to why the Visitor has come to the site, and if there are to present them with a suitable message pointing them in the right direction.

I have tried request.getHeader("referer"), but this only seems to work for internal links and not for links in from say a Google Search.

So for instance, if we were able to pick up the following URL "", then we could detect the word "staplers" in the middle and present a message relating to Staplers to the Visitor.

No I don't sell Staplers, it was the first example that came to mind !!!

So how do I get the Full URL of the Previously visited page ?

See More: Java/JSP - Access to Previous URL

Report •

September 28, 2009 at 09:30:27
Hi, have you also tried:

if (document.referrer.indexOf('staples') != -1) {
// write-code-to-display-your-staples-info

Report •

September 28, 2009 at 09:39:47
I dont have a problem with the logic around how to display my message. My question was more about how I get the URL.

That looks like a JavaScript snippet as opposed to Java code in a JSP, I am not averse to that, but would "document.referrer" using my example return




Obviously the latter would be of no use to me at all.

Report •

Related Solutions

Ask Question