views:

15

answers:

0

Hi All, I am not able to set cookie domain in my webapp(WebApp.mydomain.com).

My sample code is given below, my webapp name is WebApp.mydomain.com, this has got two jsp pages, one for creating cookie and other one is for reading the cookie.

CreateCookie.jsp


Cookie cookie = new Cookie("id","123");
      cookie.setDomain(".mydomain.com");
      cookie.setPath("/");
      response.addCookie(cookie);

ReadCookie.jsp


Cookie[]cks = request.getCookies();

      for(int i=0;i<cks.length;i++){
  out.print("cookie found.............................   "+cks[i].getValue());
      }

Issues:

  1. I am not able to read the cookie, if i set the domain as cookie.setDomain(".mydomain.com"); at cookie. I verified it by commenting the domain setting line.

  2. The reason for setting the domain is, I have another web application "WebApp1.mydomain.com" which is supposed to read this cookie which is created in "WebApp.mydomain.com" application.

  3. Is it possible to access the cookie across the applications as the cookie domain and path are been set. (i.e) From WebApp.mydomain.com to WebApp1.mydomain.com?Please share your inputs

Thanks, Sundar