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

Cookies associated to a Session

rags singh

Joined: Dec 29, 2011
Posts: 1

I am reading Head First Servlets and JSP and in the topic dealing with Cookies it says that cookies can be retrieved from a client request using the

My question is if cookie is used to identify a single client , how can a servlet get a cookie array from a request (from a single client) ie how can a client send multiple cookies and under which scenario ?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

rags singh wrote:how can a servlet get a cookie array a request from a single client ie how can a client send multiple cookies and under which scenario ?

Sorry, but something seems to have gone wonky with that sentence and I'm not sure what it is that you are asking.

[Asking smart questions] [About Bear] [Books by Bear]
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

Server can send many cookies in response to the client.

In return, cookie being sent in request to the server is based on "path" and "domain" set in cookie while sending in response...

If the Cookie path is set to particular context path "/webApp" and domain ""

Then, cookies will be sent along with request with URL path of the resource under "" from the client.

If its "/" and domain "",

Cookies will be sent to any web application under "" domain.

SCJP 6 [SCJP - Old is Gold]
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
As mentioned, the server can send multiple cookies, and when the client sends a request, all the associated cookies are sent in the cookie array. Then you can iterate this array to get a specific cookie.

So much trouble in the world -- Bob Marley
Ankush Kaundal
Ranch Hand

Joined: May 12, 2011
Posts: 36

Yes there can be many cookies sent by the server and you can even create your own cookies and get it added via response.
Kumaravadivel Subramani
Ranch Hand

Joined: Jul 05, 2008
Posts: 171

It's not always single cookie or multiple cookies which can be send with request by server, but you can have one or more cookies in the request.

No pain, No gain.
OCJP 1.6, Liferay Certified Developer 6.1
I agree. Here's the link:
subject: Cookies associated to a Session
It's not a secret anymore!