OK, web programming geeks (I know you’ve got to be out there), try this one on for size…
I’m a programmer with an internet company, and our site is set up using JSP with Java servlets to process the data and send XML messages to our application servers. We’re working on a fairly major re-architecting (is that a word?), and I need to know if there is a way to detect whether the user came to a page via a bookmark, as opposed to a standard click-through via a fresh link.
Is there some variable or flag that gets set somewhere (in the HttpServletRequest or HttpSession objects, maybe) that would let us figure this out? Our CTO says we need to know the difference (I don’t know why at this point; maybe some sort of security consideration).
Any assistance the Teeming Millions can give would be much appreciated.
I am not aware of anyway to detect whether someone has specifically come from a bookmark and I would suspect that this is not possible. However, one thing that you can do is check their referrer. If they are coming from a link(i.e. anywhere else on the site) then the referrer will be non-null and not empty. In most cases, the only way there would be a null/empty referrer is if they typed in the url directly or if they came from a bookmark. I think you can use the HttpServletRequest’s getHeader(String headerToGet) method to find the referrer. So, try:
if (request.getHeader(“Referrer”) == null || “”.equals(request.getHeader(“Referrer”)))
{
// they probably came from a bookmark
}
Of course, this method is probably not going to be accurate 100% of them time but it may be the best you can do.
Thanks, eBathory. I did a little testing, and found that, in fact, the Referer is null (or possibly blank–I tested for both, as you suggested) when coming from a bookmark. However, this is going to need to be coupled with setting things up so no pages are cached, because accessing a bookmark from the same session in which you set up the bookmark results in the browser getting the page out of the cache, without going through the servlet engine (Tomcat, in this case) at all.
The short version is: Thanks! I’ve run the idea past our tech team, and they seem to think this could be the solution we’re looking for (haven’t heard from the CTO yet, though).
Do you know of any other situations in which the Referer might be null or blank?
The referer header isn’t required, so some browsers don’t include it regardless of whether it would have a meaningful value or not. This isn’t true of most browsers, but I’ve run into a few in the past that didn’t use it. The main thing this means is that you have to have a meaningful response if it’s missing, but since an empty value is valid in the referer header even if it is included, this isn’t really a problem.
Any chance you remember which browsers and/or how long ago this was you noticed this? If it’s really a minority browser issue, I’m probably not going to worry about it, but if it’s more recent/prevalent, we’re going to have to do some thinking about it.
I don’t recall, but it was some seriously minority browsers like a text-to-speech browser and an offline browser like WebWhacker. It only came up because someone was trying to force users to come through a gateway by making sure the referer had a certain value. These browsers didn’t pass it at all, so those few users couldn’t get in. However, in a normal situation, a blank referer is valid (e.g. if you type in the URL) so these browser that don’t pass anything won’t “break” your app.
I hope someone else can provide a more comprehensive answer than me but I do know that the big three browsers(Netscape, IE, Mozilla) will send the referrer header. Also, I would imagine that right now only relatively obscure browsers would not send such a header.
If I had to guess, I would say that the only browsers that wouldn’t send them would be older text-only ones such as maybe Lynx or something like that. If you have access to a windows web server running IIS then you can get it to log the referrer on all hits so that after a few days of running you would probably have enough field data to be able to determine what, if any, browsers you are getting that don’t send the referrer header. You may be able to do this on an apache webserver as well.