JSP implicit Session object (II)
17 March 2008In this post, I will specifically talk about few useful session object methods.
The getAttribute method of session object is used to return the object (java.lang.Object) with the specified name given in parameter. If there is no object then a null value is returned.
Example:
String userName = (String) session.getAttribute("username");
So, as a JSP developer, you may save objects (String, ArrayList, HashList, Vectors etc) into session object and can retrieve whenever you need.
getAttributeNames method of session object is used to get all the stored session objects (current session). It returns an enumeration object and we can iterate through it to deal wit all the session objects.
Example:
enumObjects = session.getAttributeNames( ) ;
The above statement returns enumeration of objects, which contains all the unique names stored in the current session object in the enumeration object enumObjects.
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: JSP implicit Session object (II)