By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,818 Members | 2,121 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,818 IT Pros & Developers. It's quick & easy.

JSP & JavaScript: don't grok cookies?

P: n/a
I have a JSP which does request.addCookie(cookie), then <c:redirect/>
to a second JSP. Said second JSP reads the given cookies via JSP and
sees that all is well: the cookies have arrived. Said second JSP
*also* has some JavaScript code reading the same cookies, but they are
not found.

How come that JavaScript can't read the cookies set via JSP?

I create the cookies in the first JSP like this:

Cookie cook = new Cookie("foo", "bar");
cook.setPath("/evITA-Web");
response.addCookie(cook);

And the JavaScript code to read them looks like this:

function get_cookie(name) {
var regexp = new RegExp(name + "=([^;]+)");
var cookie_match = document.cookie.match(regexp);
if (cookie_match) {
return cookie_match[1];
} else {
return null;
}
}

I'm trying this out in IE 6 on W2k/pro. The server side is a Tomcat
5.0.16.

Kai

Jul 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
nos
you need the javaAintJavascript()

"Kai Grossjohann" <ka*@emptydomain.de> wrote in message
news:87************@emptyhost.emptydomain.de...
I have a JSP which does request.addCookie(cookie), then <c:redirect/>
to a second JSP. Said second JSP reads the given cookies via JSP and
sees that all is well: the cookies have arrived. Said second JSP
*also* has some JavaScript code reading the same cookies, but they are
not found.

How come that JavaScript can't read the cookies set via JSP?

I create the cookies in the first JSP like this:

Cookie cook = new Cookie("foo", "bar");
cook.setPath("/evITA-Web");
response.addCookie(cook);

And the JavaScript code to read them looks like this:

function get_cookie(name) {
var regexp = new RegExp(name + "=([^;]+)");
var cookie_match = document.cookie.match(regexp);
if (cookie_match) {
return cookie_match[1];
} else {
return null;
}
}

I'm trying this out in IE 6 on W2k/pro. The server side is a Tomcat
5.0.16.

Kai

Jul 20 '05 #2

P: n/a
> "Kai Grossjohann" <ka*@emptydomain.de> wrote in message
news:87************@emptyhost.emptydomain.de...
I have a JSP which does request.addCookie(cookie), then <c:redirect/>

"nos" <no*@nospam.com> wrote in message
news:940Eb.581886$Fm2.540014@attbi_s04... you need the javaAintJavascript()


The 'J' in JSP does not stand for JavaScript, nos.

(and please do not top post)

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
Jul 20 '05 #3

P: n/a
nos
oops, sorry
what is top post?

"Andrew Thompson" <an******@bigNOSPAMpond.com> wrote in message
news:Bh******************@news-server.bigpond.net.au...
"Kai Grossjohann" <ka*@emptydomain.de> wrote in message
news:87************@emptyhost.emptydomain.de...
I have a JSP which does request.addCookie(cookie), then <c:redirect/>


"nos" <no*@nospam.com> wrote in message
news:940Eb.581886$Fm2.540014@attbi_s04...
you need the javaAintJavascript()


The 'J' in JSP does not stand for JavaScript, nos.

(and please do not top post)

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site

Jul 20 '05 #4

P: n/a
"nos" <no*@nospam.com> wrote in news:Dk0Eb.575895$Tr4.1550762@attbi_s03:
oops, sorry
what is top post?


http://www.html-faq.com/etiquette/?toppost
Jul 20 '05 #5

P: n/a
"nos" <no*@nospam.com> writes:
you need the javaAintJavascript()


Huh? I know that Java ain't JavaScript.

Kai
Jul 20 '05 #6

P: n/a
"nos" <no*@nospam.com> wrote in message
news:Dk0Eb.575895$Tr4.1550762@attbi_s03...
oops, sorry
what is top post?


...hmmm. Are you extracting the urine?

In any case, for those that are not aware..
http://www.allmyfaqs.com/faq.pl?How_to_post

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
Jul 20 '05 #7

P: n/a
"Thomas Schodt" <news0310@xenoc.$DEMON.co.uk> wrote in message
news:Xn*******************@158.152.254.254...
"nos" <no*@nospam.com> wrote in news:Dk0Eb.575895$Tr4.1550762@attbi_s03:
oops, sorry
what is top post?


http://www.html-faq.com/etiquette/?toppost


Thanks Thomas, when I googled it I was
swamped with hits. That was the one I
was looking for.
Jul 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.