For every user request, unique session id will be created.
Example
If there are 10 users, 10 sessions are created.How does the web container knows,this particular session is used for user1 ... and so on.
For every user request, unique session id will be created.
Example
If there are 10 users, 10 sessions are created.How does the web container knows,this particular session is used for user1 ... and so on.
The most common way is using cookies. There is a cookie, usually named "JSESSIONID" which has the unique identifier of a session. When it is attached to requests, the server uses it to link the request to the proper user session on the server.
There are also other techniques, but I can't remember all of them. There was a possibility to serilialize the session and send it between the server and the client and other methods like this, but session cookies are the most common by far.
For every user request, unique session id will be created.
No. For every user a distinct session ID is created.
If there are 10 users, 10 sessions are created.
Exactly. You've just contradicted yourself. Each of those users can submitted multiple requests within the same session.
How does the web container knows,this particular session is used for user1..and so on.
Via a session ID communicated to the browser via a cookie, and returned to the server on subsequent requests via the same cookie or a JSESSIONID parameter in the URL.
A simple overview is :
When a user visits a website for the first time, the servlet container will create an HttpSession
object and store it on the server.
This HttpSession
object is tagged with some long unique Id (session.getId()).
Also, the server now sets a Cookie in the response header with JSessionID as the key and the long unique Id as the value.
When, the user makes another request, the browser passes on the cookie in each subsequent request (in the request Headers).
By this the servlet container identifies each session per user.