• Post Reply Bookmark Topic Watch Topic
  • New Topic

Server needs to know whether browser supports cookies  RSS feed

 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a servlet that needs to verify that the browser supports cookies. If not, it should issue an error message "you must enable cookies to use this site".
(You may argue with this business approach, but that's what we want... even though we know of "url rewrites").

But how can a Servelt know whether the browser supports cookies ?
Are there any recommendations or ready-made APIs for it?

So far I could only think of ways to know within the *second* page (have one "welcome page" and require that other pages be accessiable only through this "welcome page". Then, I guess you can prepare a "test" cookie in the welcome page, and the browser must send it back to the 2nd page, otherwise you know cookies are disabled).

But I think I've seen some websites which manage to tell within the very first page: if my browser has disabled cookies, the "welcome page" tells me so immediately... how come ?

Thanks
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use the method isRequestedSessionIdFromCookie of the HttpServletRequest interface. It will only work if you use sessions.


HttpServletRequest


The container will use cookies for tracking sessions if the browser of the client supports cookies.
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for this answer.
Could I please ask - isn't it expected to work only on the second page?
The very first time a user visits my site and arrives at the "welcome" page, he won't have any cookies to send me, will he?
Or am I missing something?

Thanks again
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's right.
You won't be able to test for cookie support on the first hit (unless they've been to your site before).
 
Piash Chaudhuri
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sol Ma-Orn, sorry for posting in your topic.

@Ben Souther,
Here is a jsp site that detects if cookie is disabled in your browser even when you visit them for first time.

For IE:
http://10.240.43.216/webLogin.jsp

Non IE:
http://10.240.43.216/nonie_webLogin.jsp

How do the do this ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!