Sometime while developing web application it is necessary to interact with the different values of the Session object.
Display session value Using Servlet
Sometime while developing web application it is necessary to interact with
the different values of the Session object. In this example we will explore the different
values of the Session object and then learn how to use it in our programming
You will learn how to find all the session related information like:
getId. This method is used to find the identifier of the session
which is unique.
isNew. This method is used when find, whether session is newly
created or preexisted. If session has never seen by user then this method
return "true" but if session is preexisted then it return
getCreationTime. This method is used to find the creation time of
session. To use of this method we can find the following details about
session i.e. day, month, date, time, GMT(Greenwich Mean Time) and
year will be displayed.
getLastAccessedTime. This method is used to find the last accessed
time of session. It returns the time, in milliseconds.
getMaxInactiveInterval. This method returns the total time, in
seconds, during which session remains active if user does not accesses the
session for this maximum time interval. After this time the session will be
invalidated automatically. A negative value indicates that the session should never
Here is the sample code for HttpSessionDisplay.java: