File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes JSP and Javascript Cookies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP and Javascript Cookies" Watch "JSP and Javascript Cookies" New topic

JSP and Javascript Cookies

Vikas Aggarwal
Ranch Hand

Joined: Jun 22, 2001
Posts: 140

My simple question is whether I can read cookies set by javascript in JSP and viceversa?

Philip Shanks
Ranch Hand

Joined: Oct 15, 2002
Posts: 189

The answer to your question is yes.

And now I will anticipate your follow-up question: How?

Hint: use the implicit request object in JSP, figure our how that relates to the HttpServletRequest object and how to access its method for retrieving cookies from the request object. You will likely wind up looping through a Cookie[] array.

In javascript use the cookie property of the document.

Good luck!
[ February 09, 2007: Message edited by: Philip Shanks ]

Philip Shanks, SCJP - Castro Valley, CA
My boss never outsources or has lay-offs, and He's always hiring. I work for Jesus! Prepare your resume!
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Cookies are cookies. Whether set in Javascript, or by other means, they all use the same underlying mechanisnms.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: JSP and Javascript Cookies
It's not a secret anymore!