• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to find that Cookies are supported by the browser or not

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks,
How we can find that Cookies are supported by the browser in servlet?

Awais
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is some info for you of how session works.

you do have to tell container that you want to create or use a session, but container takes care of generating the session ID, creating new Cookie object, stuffing the session ID into the cookie; and setting the cookie as part of the response.

Container tries to use cookies first. If cookies are disabled container falls back to URL rewriting, but you will have to do extra work of encoding all the URLs.

Keep in mind, if the container doesn't get a session Id from the client, container wouldn't know that this is the next request from the client. The container won't have any way to know that it tried cookies the last time, and they didn't work. THE ONLY way the container can recognize that it has seen this client before is if the client sends a session ID.

Now the next request from this same client, it will have the sessionID appended to the request URL, but if the client accepts cookies, the request will also have a session id cookie. When servlet calls request.getSession(), the container reads the session Id from the request, find the session, and thinks to itself that this client accepts cookie so it ignores request.encodeURL() calls, or else it will use URL rewriting.

You as a developer you shouldn't be bothered whether client has disabled cookies or not, as container by itself will fallback to URL rewriting.

HTH,
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The easiest way can be trying a cookie in JavaScript. If you can't use JavaScript then you can display a probe page with some token in all links and request a session creation. If at navigation from this page you will see freshly created session, then it's more likely browser's cookies are disabled.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Set a cookie oan the response, see if you can read it back. If you can, cookies are supported.
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bosun Bello
You solution is much better. However when you do cookie testing you should aware that browser can handle session and permanent cookie differently.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic