Session Management In Servlet

Session Management In Servlet is one of the most common task for any web based application. As we know that HTTP is a stateless protocol, So what ever data client browser sends to the server and once server generates the response then all the data send by client browser will be destroyed. in other word the server will forget everything related to client/browser state. If client browser sends another request to the server then server does not know anything about previous request(client/browser state). So in order to maintain the session between client browser and server, we use HttpSession servelt API in Servlet.

 Session Management using HttpSession API :-

session-management-in-servlet
In above example , when user submits the form after entering his username and password to login into the application. This request goes to server and server is authenticating it. Once login and password are correct, then session is created for the user and "login" attribute is added into the session and finally request is forwarded to the user's home page.

 Accessing the attribute from the session in servlet :-

accessing-attribute-from-session