This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Software Teaming: A Mob Programming, Whole-Team Approach and have Woody Zuill and Kevin Meadows on-line!
See this thread for details.
  • 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

How to check if cookie is enabled or not

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to know whether the client browser is having its cookies as enabled or disabled. I have to do this in the code.
Is there any way to do this in JSP or normal javascript/HTML
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I hope that there is only way for this. The solution is to call a servlet will set cookies. The servlet output, the HTML page should immediately refresh to some servlet which will try to retrieve the cookie set by the previous servlet. If it is able to retrieve the cookie, then the client browser accepts cookie else not.
In this regard, let me tell you that there are two types of cookies, one is persistent cookies and the other is non-persistent cookies. This could be seen better with netscape navigator. Session maintenance with getsession() method uses non-persistent cookies. setCookie() method uses persistent cookies. The solution I gave above is for persistent cookies. You can use the same solution but use the getsession() method to test for non-persistent cookies. Hope you understood the solution.

Originally posted by Ashutosh Uprety:
I want to know whether the client browser is having its cookies as enabled or disabled. I have to do this in the code.
Is there any way to do this in JSP or normal javascript/HTML



------------------
 
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried something like that.... Waiting for the server to start up in debug mode. Let's see what happens!
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i could not understand to check the cookie is enabled or not is quite complicated. why the http header or request object does not contain those information?

i would like to know how to check as well, currently i only know how to check that by using javascript. but i prefer to use servlet...

any ideas???
 
Sheriff
Posts: 67693
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Set a cookie, then read it back on the next request. If it's there, cookies are enabled.

And no, there is no header to inform us whether cookies are enabled or not.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic