0

Hello i am trying to use cookie at my site. I used this code for set the cookie

  try{
       Cookie cookie1 = new Cookie("thesiteid", Integer.toString(site_id));
       cookie1.setDomain("localhost");
       cookie1.setPath("/");
       cookie1.setMaxAge(24*60*60*365);
       response.addCookie(cookie1); 
       System.err.println("Set cookie");
   }
   catch (Exception e){
       System.err.println("Error in creating the cookie: "+e.getMessage());
   }

The problem is that is not working at chrome and i am not sure if it does not work to other versions of IE. How i can make a more universal create cookie?
Thank you very much

4
Contributors
5
Replies
8
Views
4 Years
Discussion Span
Last Post by jayvee88
0

Seems there is no issue with this code.
Have you checked if cookies are not disabled in your browser?

And how are you checking this cookie on your web page?
can you put here that piece of code that shows how you are testing this cookie in the jsp? or in any other servlet?

0

i have checked that the cookies are not desabled. It is working at mozilla,safari,ie but not chrome for some reason.
To check the if the cookie exists i use this code

Cookie[] cookies = request.getCookies();
    for(int i = 0; i < cookies.length; i++) { 
            Cookie cookie1 = cookies[i];
            if (cookie1.getName().equals("thesiteid")) {
               // System.err.println("thesiteid = " + cookie1.getValue());
                cookiesiteid = Integer.parseInt(cookie1.getValue());
                foundCookie = true;
            }
    }

Something is wrong and does not work at chrome. Maybe the command cookie1.setDomain("localhost"); has a problem and not work at chrome

0

See, cookies are dependant on browser setting if browser is enabled to accept cookie then
the cookie mechanism works but if he /she disabled it then no matter how hard u try the mechanism will not work.So,to solve your problem you have to check wheather in your chrome bowser setting allows to accept cookie or not.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.