Forums Register Login
Unable to understand output of these servlets
I am new to JSP & servlets. I am unable to understand the output of the 'CheckSession' (code given below) servlet. If i access CheckSession directly it gives Cookie Array length as 1. But if i first go to TestSession which forwards request to jsp(the jsp does nothing but has a href link to CheckSession Servlet), and from jsp to CheckSession, the cookie length is 2. I dont understand why its 2. Please help.

Below are the two Servlet's codes:

Did you check to see what the two cookies were? This could give you a clue as to where they came from.
The output when i view CheckSession through TestSession servlet is:
Here is the output: check 2 Bhanwala

The output when i view CheckSession directly is:
Here is the output: check 1 Bhanwala

I printed all the cookies in output in CheckSession servlet. For the first output the JsessionID and its value is in the output along with the value 'bhanwala' which i set myself. Can you tell me why jsessionID is there for first output and not for 2nd.
I think my question can be answered if it is clear when the JsessinID is added in the cookie. From my above two output it looks like Jsession ID is added in the cookie when the 2nd request comes from the same client for the same session. But not sure if this is correct
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

All times above are in ranch (not your local) time.
The current ranch time is
Oct 24, 2017 02:13:00.