• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cookie question

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic