This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Servlets and the fly likes how to know if cookies are enabled? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to know if cookies are enabled?" Watch "how to know if cookies are enabled?" New topic

how to know if cookies are enabled?

Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
Hi all,
How can we know if cookies are enabled via just the request object we have. I know the way via which we can,
- write a cookie
- read it back and if we do get value it means cookies are enabled
BUT I want to know if there is anyway I can know this information w/o doing these two steps. The reason is, I thought I would write a CookieManager class to add,delete,parse cookies...Now that class would be a stand alone object used in Servlet/JSPs to which I plan to pass a request object and want to have a method in there that says "ifCookiesEnabled()" know...
I am not very optimistic about the answer here but I am throwing question...
Nor I am sure how much worth this CookieManager would be...
Eelco den Heijer
Ranch Hand

Joined: Jan 17, 2002
Posts: 61
You already gave the right answer to you own question; that's the way to check cookie-awareness of the client. There is no method in the HttpServletRequest to check for cookie-awareness (not even in J2EE 1.4). Enabling this would require all browsers to support such a query ("Do you support cookies Y/N?") from the server. Anyway, your solution will do the trick anyway

== <br />Rgrds,<br />Eelco<br /> <br />SCJP, SCJD, SCBCD, SCWD, SCEA
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873

This means, I can't write a single method in a CookieManager class I have that says, ifCookiesEnabled(HttpServletRequest request)...
Thanks for confirming my belief , Eelco.
Have you checked out Aspose?
subject: how to know if cookies are enabled?
It's not a secret anymore!