Show TOC Start of Content Area

Process documentation Session Tracking with Servlets  Locate the document in its SAP Library structure

Purpose

You can use HTTP sessions and the corresponding API in your servlets to be able to keep track of client actions performed within your web application. Ability to preserve client state over several request-response cycles is a crucial feature of most real business applications. Furthermore, using additional techniques, you can make the state persistent, thus providing your applications with a degree of fault tolerance.

You can use both cookies, or URL rewriting to exchange session related information between the client and the server. Cookies are used by default, but in cases when client browser does not accept or support cookies, URL rewriting is the alternative.

Process Flow

The session tracking works the following way:

...

       1.      When the very first request from a client comes to the J2EE Engine, a session object is created and associated with that client. The object lives on the server for its lifetime. Servlets use it to store information about that particular client. The J2EE Engine’s Web Container generates a unique session ID and sends it with the response to the client using JSESSIONID cookie, or URL rewriting.

Note

It is also possible that a session is created in the following case: the client request that is received contains a JSESSIONID cookie but no HTTP session with that ID exists on the corresponding server process. Therefore, the Web Container creates a session and maps it to the ID that came with the client request.

       2.      On each consequent request from the client, the Web Container looks up the HttpSession object that is associated with the request using the session ID.

       3.      The servlet retrieves the session-related information that is stored on the server-side.

       4.      If client performs any actions that need to be stored, the servlet associates the corresponding information with the session.

       5.      After the session is completed (or timed out due to inactivity) the session object is removed from the server.

 

End of Content Area