aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 1871
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: 1871

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.
I agree. Here's the link:
subject: how to know if cookies are enabled?
Similar Threads
How to use ckookie in jsp
Shopping carts and sessions and cookies, oh my!
Applet cookie access and retrieval
CookieManager doesn't send cookies?
Tomcat + JCIFS + Apache + mod_jk + Java client == error 401