wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Sending a session cookie in the response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Sending a session cookie in the response" Watch "Sending a session cookie in the response" New topic
Author

Sending a session cookie in the response

Jose Esteban
Ranch Hand

Joined: Nov 28, 2004
Posts: 102
In page 231 of HFSJ you can read:
------------------------------------------
Sending a session cookie in the response
HttpSession session = request.getSession();

... everything else happens automatically.
...
You don't set the Cookie into the response (under the Set-Cookie header).
------------------------------------------

Since the getSession() method doesn't have any reference to the response, I don't understand how this method can set a cookie into the response.

Anybody has an explanation?
Ganeshji Marwaha
Greenhorn

Joined: Sep 16, 2004
Posts: 27
I will try to attempt this question.

The container is the one who provides the servlet with reference to request and response objects it creates. so, obviously the container will have a reference to the response object, until the response is completely written to the client. Then both request and response may be GC-ed.


-- Ganeshji Marwaha<br />SCJP<br />SCWCD<br />SCBCD<br />MCP, MCP+SB, MCSD
Bassam Zahid
Ranch Hand

Joined: Mar 09, 2005
Posts: 61
I think this is done by the container by "adding a header containing cookie object" in response object.

The container might do it this way:

Of course, the container has references to request / response and other objects.


BS<br />SCJP 1.4 88%<br />SCWCD 1.4 86%
Jose Esteban
Ranch Hand

Joined: Nov 28, 2004
Posts: 102
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending a session cookie in the response
 
Similar Threads
HFSJ Page 231, under 2nd Heading
cookies
session id - one last basic question for Sunday
Applet to Servlet communication using https
What is wrong with my cookie?