• 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

setting and retrieving cookies using javascript on a jsp

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I need to set a cookie on a jsp with some value stored in a java variable "adID". I would need to do that after the page loads, so I use:


I would need to retrieve the cookie value on another jsp. I have the retrieve method for the cookie in javascript.

What I am not sure is how I can use this method in my jsp to retrieve the value of the cookie 'Name' into a java variable?

Any help on this is appreciated. Thank you.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nina Binde:
What I am not sure is how I can use this method in my jsp to retrieve the value of the cookie 'Name' into a java variable?


You can't save anything into a Java variable from javaScript. Think about it for a minute. The Java in the JSP executes on the server long before the page is sent to the browser where the JavaScript will execute. The Java no longer exists, so how could JavaScript interact with it?

If that's not clear, you might find this article helpful.
 
Nina Binde
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it. Thank you, Bear.
Instead, I would like to now read the cookie value in javascript and do a check (if there is cookie present, then do this. Else, do that.)
Is this possible and if yes, how can I embed this javascript code in the java without an event being triggered?

Thank you for your replies.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nina Binde:
how can I embed this javascript code in the java without an event being triggered?


I'm not sure what you mean by this. Again, the Java executes on the server, the JavaScript executes on the client. They don't have much to do with each other.

Perhaps you should back up a bit and explain what you are really trying to accomplish, and maybe we can suggest an appropriate approach.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://search.live.com/results.aspx?q=JavaScript+getCookie

There are plenty examples out on the net on how to read a cookie with JavaScript.

Eric
 
reply
    Bookmark Topic Watch Topic
  • New Topic