Total Pageviews

Monday, October 18, 2010

Session- an overview

What is a Session Object ?


Session Object is used to maintain a user session  related information on the Server side. You can store , retrieve and remove information from a Session object according to your program logic. A session object created for each user persists on the server side, either until user closes the browser or user remains idle for the session expiration time, which is configurable on each server.
How to create Session object and use it for storing information ?


This code will get the Session context for the current user and place values of count1 and count2 into MyIdentifier1 and MyIdentifier2 respectively


HttpSession session = req.getSession(true); //Creating a Session instance


session.putValue ("MyIdentifier1",count1);  // Storing Value into session Object
session.putValue ("MyIdentifier2", count2); 


session.getValue(MyIdentifier1); // Prints value of Count


session.removeValue(MyIdentifier1); // Removing Valuefrom Session Object

No comments:

Post a Comment