• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cookie question

 
Siyaa Hoffman
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1873
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Siyaa,
It should not happen. Can you please tell us how you are setting the cookie via Javascript?
Thanks
Maulin
 
Siyaa Hoffman
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1873
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic