JSP & JavaScript: don't grok cookies?

K

Kai Grossjohann

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top