Home Java TutorialServlets Session Tracking Using Servlet

Session Tracking Using Servlet

by anupmaurya
3 minutes read

A session is a collection of HTTP request , over a period of time. A session is specific to the user and for each user a new session is created to track all the request from the user.

In servlet session tracking can used to track the user state. Session tracking is also known as session handling, it is a mechanism used to maintain the state of a user within a series of requests across some period. We can say that session tracking is a means to keep track of session data. This data represents the data being transferred in a session.

Http protocol is a stateless so we need to maintain state using session tracking techniques. Each time user requests to the server, server treats the request as the new request. So we need to maintain the state of an user to recognize to particular user.So, There are some technique which keeps the manage each session as follows:

Session Tracking Techniques

There are four techniques used in Session tracking:

  1. URL Rewriting
  2. Hidden Form Field
  3. Cookies
  4. HttpSession

URL Rewriting

With URL rewriting every local URL the user might click on, we can pass extra information. This extra information can be written in the form of added parameters, extra path or some specific change in the URL. As a limited space is available in rewriting the URL , the extra information is limited to a unique session ID. With this mechanism, you can append a client’s session data to the request path as a query string or as a part of path info.

Hidden Form Fields

Hidden form field is a type of HTML form field, but remains hidden in the view. Hidden form is a form of session tracking which saves the information in client browser itself. In this mechanism invisible text field is used to maintain the state of an user.


A cookie is a file containing the information that is sent by a Web server to a client. Cookies transmitted through the HTTP to client .Cookies are saved at the client side for the given domain and path. The cookies file persist on the client machine and the client browser returns cookies to the original server. The servlet API provides a class named cookie under the javax.servlet.http package. javax.servlet.http cookie object is designed to represent a HTTP cookie, which provides a convenient way to exchange data of a cookie between container and servlet. The javax.servlet.http.cookie class consist of one constructor with two String arguments. The first argument take cookie name and second take cookie value.

HTTP Session

In this Mechanism the web container maintains the users data and tracks the users session by using URL rewriting or cookies. This mechanism helps to maintain a unique identity for each of session without using URL rewriting or cookies.

You may also like

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.