Session Tracking Using Servlet

331 views
optmiize_your_resume_1

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.

Cookies

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.

Session Tracking Using Servlet

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.

20%off for Ink 280 281

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More