[Logo]
Forums Register Login
setting and retrieving cookies using javascript on a jsp
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.
 
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.
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.
 
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.
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
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Nov 18, 2017 18:26:52.