467,877 Members | 1,130 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,877 developers. It's quick & easy.

JSP & JavaScript: don't grok cookies?

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
  • viewed: 2402
Share:
7 Replies
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
> "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
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
"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
"nos" <no*@nospam.com> writes:
you need the javaAintJavascript()


Huh? I know that Java ain't JavaScript.

Kai
Jul 20 '05 #6
"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
"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.

Similar topics

reply views Thread by Gowhera Hussain | last post: by
2 posts views Thread by Don Grover | last post: by
4 posts views Thread by changed | last post: by
1 post views Thread by John Taylor-Johnston | last post: by
1 post views Thread by Srinivasa Raghavan | last post: by
7 posts views Thread by bhavin30 | last post: by
reply views Thread by jack112 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.