views:

45

answers:

4

I understand that if we use the following statement

HttpSession session = request.getSession();

Will create the Unique session id, Create Cookie and associate Cookie with the Session id.

and helps the container to keep track and identify the clients.

Yes, My question, is there a possibility for me to see the cookie header and Unique Id created by this statement request.getSession()?

A: 

You can use session.getId() for the ID I believe. Not sure about the header.

edl
A: 

You can retrieve a HTTP Header using HttpServletRequest.getHeader.

Although a session can be created by calling HttpServletRequest.getSession(true) it's rather done by the webcontainer. As edl already wrote HttpServletRequest.getSession().getId() returns the session id.

stacker
+1  A: 

You can see it using any HTTP header tracker tool. Firebug for example shows the headers in the Net panel. Here's a screenshot (click here for full size):

alt text

Any newly created cookie will appear as Set-Cookie header in the response. The client will send the same value back as Cookie header in the subsequent requests in the same session so that the server can identify the client session. For a JSP/Servlet webapplication, your interest is the cookie with the name JSESSIONID.

BalusC
A: 

I found more information in the following URL http://www.javacertifications.net/javacert/session.jsp

harigm