The Session Object in JSP

By: Sathya Narayana Emailed: 1700 times Printed: 2204 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

The session object is an instance of a class that implements the javax.servlet.http.HttpSession interface. You can use it to store session state for a user, and it makes the following methods available.

getAttribute() returns the Object bound to the specified name in this session or null if it doesn't exist:

public Object getAttribute(String name)

getAttributeNames() returns an Enumeration of String objects containing the names of all the objects bound to this session:

public java.util.Enumeration getAttributeNames()

getCreationTime() returns the time when the session was created in milli-seconds since midnight January 1, 2003, GMT:

public long getCreationTime()

getId() returns a String object containing a unique identifier for this session:

public String getId()

getLastAccessedTime() returns the last time a client request associated with the session was sent. The return value is the number of milliseconds since mid-night January 1, 1970, GMT:

public long getLastAccessedTime()

getMaxInactiveInterval() returns the number of seconds the server will wait between client requests before the session is invalidated. A negative return value indicates that the session will never time out:

public int getMaxInactiveInterval()


getServletContext() returns the ServletContext of this session:

public ServletContext getServletContext()

invalidate() invalidates the session and unbinds any objects bound to it:

public void invalidate()

isNew() returns true if the server has created a session that hasn't yet been accessed by a client:

public boolean isNew()

removeAttribute() removes the Object bound to the specified name from this session:

public void removeAttribute(String name)

setAttribute() binds an Object to the specified attribute name in this session. If the attribute name already exists, the Object passed to this method will replace the previous Object:

public void setAttribute(String name,
Object value)

setMaxInactiveInterval() specifies the number of seconds the server will wait between client requests before the session is invalidated. If a negative value is passed to this method, the session will never time out:

public void setMaxInactiveInterval(int interval)

These methods are deprecated and shouldn't be used in new code—they exist for compatibility with existing code:

public HttpSessionContext getSessionContext()
public Object getValue(String name)
public String[] getValueNames()
public void putValue(String name,
Object value)
public void removeValue(String name)


JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(1)


1. View Comment

nice

View Tutorial          By: knraju at 2012-04-13 13:49:57

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Sathya Narayana
Querying Data with the JSTL in JSP
Deleting Data in MySQL
Modifying data and using WHERE clause in MySQL
Querying the Database in MySQL
Inserting Data into Tables in MySQL
Changing the Structure of an Existing Table in MySQL
The Exception Object in JSP
The Application Object in JSP
The Session Object in JSP
The Out Object in JSP
The Response Object in JSP
The Request Object in JSP
Tag Libraries in JSP
Scriptlets and Expressions in JSP
Declarations in JSP

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
What is JSP?
An Example Using Servlet Initialization and Page Modification Dates
Debugging Servlets
Servlets
Select Object
The Basic Syntax Expression Language in JSP
Comparison operators in JSP
The Differences Between Simple and Classic Tags in JSP
Sending Email using JSP
Getting HTTP Request Headers in a JSP
The Session Object in JSP
JSP Alert Example
Cookies using JSP or Java Bean
Click to Activate and Use this control
The JSP Program running first Time.
Most Emailed Articles (in JSP)
Declaring variable in JSP
What is JSP?
Cookies using JSP or Java Bean
Click to Activate and Use this control
The JSP Program running first Time.
Scriptlets
Server Side Programming
Syntax For JSP Declaratives
Embedding java codes in jsp sciptlets
Tags using in jsp
JSP pages in servlet
Combining Scriptlets with HTML
JSP Directives
Form processing in JSP
JSP Program for display Date