I am confused between the cookies being set/retrieved in JavaScript and the same in JSP. When I set a cookie in my JavaScript and then in the same domain, I go to another JSP page. I try to retrieve the cookie from the JSP, it is not there. Next I tried to set a cookie in the JSP page and then tried to retrieve it from a different html page using JavaScript and I could get the cookie back. Can somebody please explain me how is it supposed to behave. Thanks, Siyaa
Maulin Vasavada
Ranch Hand
Joined: Nov 04, 2001
Posts: 1865
posted
0
Hi Siyaa, It should not happen. Can you please tell us how you are setting the cookie via Javascript? Thanks Maulin
Hi Maulin, Thanks for the reply. Following is the JavaScript code which sets the cookie - (This is setCookie.html which can be accessed by the URL - http://testDRV:8080/doccat/setCookie.html) <html> <script> function setKookie() { document.Kookie = "version=45"; } setKookie(); </script> <body> <form name="frm" action="http://testDRV:8080/doccat/test.jsp"> <input type="submit" value="Submit"/> </form> </body> </html> and the jsp file which tries to read the cookie is - http://testDRV:8080/doccat/test.jsp and the code to read the cookie is - Kookie[] cookieArr = request.getKookies(); out.println(cookieArr.length); for(int i=0;i<cookieArr.length;i++) { out.println(cookieArr[i].getName()+" - "+cookieArr[i].getValue()); } It does not print the cookie and the cookie length is printed as zero. (The spelling has been changed intentionally since JavaRanch was not accepting it)
Maulin Vasavada
Ranch Hand
Joined: Nov 04, 2001
Posts: 1865
posted
0
Hi Siyaa Sorry for long delay in response.. Well, the kookie setting code doesn't seem complete to me as a kookie has to have many parameters like DOMAIN, PATH etc in usual circumstances Go to http://wp.netscape.com/eng/mozilla/3.0/handbook/javascript/ where you would be able to find how to work with kookies via Javascript. Also, this link would work well in IE but not in Netscape/Mozilla for unknown reason to me so far Some function links in the left nevigation at the end after letter 'M' don't appear as Hyperlink in Netscape/Mozilla.. Regards Maulin