Master java skills

Session Tracking in Servlets

HTTP is a stateless protocol which means every request from the client is considered as if it is coming from a new user. Thus the server doesn’t have any record of the previous requests from the same user.

This leads to a problem. If an application requires login of the user, with no tracking of the user in place, for every access to a page the user will be forced to login. This is why some kind of tracking of the same user is required. This is known as session tracking.

The interaction of a user over a period of time is referred to as a session.

=> Session tracking is the process of remembering and documenting user interactions over time. Session management is another name for it.

Why session tracking is needed

  1. Session tracking is needed to maintain the state of a user.
  2. To track the interactions of the user based on which some actions can be taken on subsequent requests
  3. One example can be on online shopping platform where your cart details have to be recorded

Session tracking techniques

  1. URL Rewriting
  2. Cookies
  3. Hidden Form Fields
  4. HttpSession object