• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Server needs to know whether browser supports cookies  RSS feed

 
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
 
Ranch Hand
Posts: 893
Java Tomcat Server Ubuntu
  • 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
 
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).
 
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 ?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!