It's not a secret anymore!*
The moose likes Servlets and the fly likes How to Check If Cookies are Enabled/Disabled Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to Check If Cookies are Enabled/Disabled " Watch "How to Check If Cookies are Enabled/Disabled " New topic

How to Check If Cookies are Enabled/Disabled

Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
Hi Everyone,

Dont know if this is already asked. Searching did not help. I was trying to implement a piece of code which checked if the cookies were enabled or disabled on the client browser. If disabled i wanted to show an error. Could you give me some pointers on how to do so? I know how to do it via JavaScript.... but wanted to implement this on the server side. Thanks for the help in advance.
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

In the servlet use javax.servlet.http.Cookie to set/read a cookie.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You can try setting a cookie then try to read it back, and see if it's sent as part of the request.

So much trouble in the world -- Bob Marley
Wendy Gibbons

Joined: Oct 21, 2008
Posts: 1107

this discussion on stack overflow seems quite complete
I agree. Here's the link:
subject: How to Check If Cookies are Enabled/Disabled
Similar Threads
How to hide the jsessionid id in my address bar in servlet programming
Determining if cookies are disabled via Servlet/JSP
Cookie Detection
how to know the Status of the cookies
How to check if cookie is enabled or not