GeeCON Prague 2014*
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
Author

Cookies associated to a Session

rags singh
Greenhorn

Joined: Dec 29, 2011
Posts: 1
Hello,

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 ?

Thanks,
ragini
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

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] [Bear's FrontMan] [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 "www.site.com"

Then, cookies will be sent along with request with URL path of the resource under "www.site.com/webApp/" from the client.

If its "/" and domain "www.site.com",

Cookies will be sent to any web application under "www.site.com" 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.


Bosun (SCJP, SCWCD)
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: 166

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
 
GeeCON Prague 2014
 
subject: Cookies associated to a Session