Servlets Session, First developer has to understand the requirement of tracking the session data HTTP is a stateless, protocol which means that whenever a client sends the request to the server, it processes the instructions and gives response back to the client, but the data may be valid or invalid, once providing a response to the client then the server does not responsible for the client data. Before learning more first user has to know that what is HTTP protocol and why HTTP is stateless Protocol.
If HTTP is a stateful protocol for multiple requests given by the client to the web application, single connection will be used between the browser window and web server across the multiple requests.
This makes clients engage connection with the web server for a long time, even though the connection is idle.
Due to this, the web server may reach to maximum connections, even though most of its connections are idle.
To overcome that problem, HTTP is given as stateless. So no client can engage connection with the web server in the long time. Moreover the connection will be closed automatically at the end of each request related to response generator.
In internet environment, since there is a chance of having a huge amount of clients for each website, it is recommended to have a stateless behavior of HTTP.
Conceptual
figure
The Stateless behavior means, while processing the current request in any web resource program one cannot use previous request data. That means while processing request2, request1 data cannot be used. Similarly, while processing request3 and request1, request2 data cannot be used.
Techniques
If a web application is capable of remembering a client data during a session across the multiple requests then that web application is called as a stateful Web application. Even though HTTP is a stateless protocol, web applications should be made as stateful web applications. For this, working with the following session tracking or session management techniques is necessary.
Servlets Session tracking is all about making web application as stateful web application by remembering client data across the multiple requests during a session. Following are the RealTime Implementation of Servlets Session tracking/session management.
Remembering email id and password during gamil.com email operations.
Remembering username and password during Net banking application.
Remembering username and password during IRCTC application.
Remembering the previous form data until last form data arrives in the online application.
Difference Between Cookies And Sessions
Sessions are server-side files that contain user information, while Cookies are client-side files that contain user information. Sessions have a unique identifier that maps them to specific users. This identifier can be passed in the URL or saved into a session cookie. Most of the sites use the second approach, saving the identifier in a Cookie instead of passing it in a URL (which poses a security risk).
Summary
Key Points
Servlets Session - Session can be defined as specific interval of time.
If HTTP is stateless then each request will be treated as new request from the web server.
To identify specific user session tracking will be used.