wood burning stoves 2.0*
The moose likes JSP and the fly likes Cookie question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Cookie question" Watch "Cookie question" New topic
Author

Cookie question

Siyaa Hoffman
Greenhorn

Joined: Jan 15, 2004
Posts: 23
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: 1871
Hi Siyaa,
It should not happen. Can you please tell us how you are setting the cookie via Javascript?
Thanks
Maulin
Siyaa Hoffman
Greenhorn

Joined: Jan 15, 2004
Posts: 23
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: 1871
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cookie question