Computing.Net > Forums > Web Development > Java/JSP - Access to Previous URL

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Java/JSP - Access to Previous URL

Reply to Message Icon

Name: gocraig
Date: September 28, 2009 at 07:47:57 Pacific
OS: Linux
Subcategory: General
Tags: JSP, Java, javascript, Previous Page
Comment:

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 "http://www.google.co.uk/search?hl=en&source=hp&q=staplers&btnG=Google+Search&meta=&aq=f&oq=", 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 ?



Sponsored Link
Ads by Google

Response Number 1
Name: Radix-64
Date: September 28, 2009 at 09:30:27 Pacific
Reply:

Hi, have you also tried:

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


0

Response Number 2
Name: gocraig
Date: September 28, 2009 at 09:39:47 Pacific
Reply:

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

"http://www.google.co.uk/search?hl=en&source=hp&q=staplers&btnG=Google+Search&meta=&aq=f&oq="

or

"http://www.google.co.uk"

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Java/JSP - Access to Previous URL

Restricting access to set browsers www.computing.net/answers/webdevel/restricting-access-to-set-browsers/3076.html

cant access webpage outside lan ..? www.computing.net/answers/webdevel/cant-access-webpage-outside-lan-/3045.html

Java Script Problem www.computing.net/answers/webdevel/java-script-problem/2090.html