javax.servlet.http
Interface HttpSession
public interface HttpSession
A HttpSession holds session-dependant data on the server side.
A servlet can request the servlet by using HttpServletRequest.getSession(...)
The handling of the Session objects is a job done by the server and
servlets together.
Object | getAttribute(String name) - XXX
|
Enumeration | getAttributeNames() - XXX
|
long | getCreationTime() - Gets this session's creation time in seconds since january 1st 1970.
|
String | getId() - Gets the unique session id.
|
long | getLastAccessedTime() - Gets the number of seconds since the previous access of this session.
|
int | getMaxInactiveInterval() - Returns the minimum time this session will be kept alive by the
server when it doesn't get accessed by a client.
|
HttpSessionContext | getSessionContext() HttpSessionContext has been depricated for
security reasons.
|
Object | getValue(String name) - Gets a object from the set of name/value pairs in the session.
|
String[] | getValueNames() - Get a list of all item names in the session.
|
void | invalidate() - Make this HttpSession unavailable for use by other servlets and tell
the server to remove this session.
|
boolean | isNew() - Returns whether this session has been freshly created.
|
void | putValue(String name, Object value) - Puts a name and value in the HttpSession.
|
void | removeAttribute(String name) - XXX
|
void | removeValue(String name) - Removes an item from the session.
|
void | setAttribute(String name, Object value) - XXX
|
void | setMaxInactiveInterval(int interval) - Sets the minimum time this session will be kept alive by the
server when it doesn't get accessed by a client.
Note: hmmm, should an interval of -1 mean that it should live forever?
|
getAttribute
public Object getAttribute(String name)
XXX
getAttributeNames
public Enumeration getAttributeNames()
XXX
getCreationTime
public long getCreationTime()
throws IllegalStateException
Gets this session's creation time in seconds since january 1st 1970.
getId
public String getId()
throws IllegalStateException
Gets the unique session id.
Every HttpSession has a Id that is unique for this (virtual) http
server.
getLastAccessedTime
public long getLastAccessedTime()
throws IllegalStateException
Gets the number of seconds since the previous access of this session.
Every time a client's request comes in the server checks (usually by
using cookies) which HttpSession object corresponds with this
particular client.
The server then sets the lastAccessedTime to the current time.
(And the isNew flag to false.) If the client has never requested anything
with this Session then this method returns -1
- number of seconds since last access or -1
getMaxInactiveInterval
public int getMaxInactiveInterval()
throws IllegalStateException
Returns the minimum time this session will be kept alive by the
server when it doesn't get accessed by a client.
getSessionContext
public HttpSessionContext getSessionContext()
throws IllegalStateException
HttpSessionContext
has been depricated for
security reasons.
Gets this HttpSession's context.
The context contains information that is the same for all HttpSessions
for this (virtual) host.
getValue
public Object getValue(String name)
throws IllegalStateException
Gets a object from the set of name/value pairs in the session.
name
- the name of the item required
- the value of the item. null if not present.
getValueNames
public String[] getValueNames()
throws IllegalStateException
Get a list of all item names in the session.
- An array of Strings containing all item names.
invalidate
public void invalidate()
throws IllegalStateException
Make this HttpSession unavailable for use by other servlets and tell
the server to remove this session. All values bound to this session
with putValue()
that implement
HttpSessionBindingListener
will be called with
valueUnbound()
.
Also: make it throw an IllegalStateException when a
servlet tries to execute one of its methods.
isNew
public boolean isNew()
throws IllegalStateException
Returns whether this session has been freshly created.
A servlet can ask the server to give the HttpSession connected with
this request/client.
The Servlet can use this method to check whether the HttpSession has
been newly created or if a HttpSession had already been created for a
previous request.
- Whether this is a new HttpSession
putValue
public void putValue(String name,
Object value)
throws IllegalStateException
Puts a name and value in the HttpSession.
If the Object implements HttpSessionBindindListener
then
the valueBound()
method of the Object will be called.
name
- the name of the itemvalue
- the value of the item
removeAttribute
public void removeAttribute(String name)
XXX
removeValue
public void removeValue(String name)
throws IllegalStateException
Removes an item from the session.
If the Object implements HttpSessionBindindListener
then
the valueUnBound()
method of the Object will be called.
name
- the name of the item.
setAttribute
public void setAttribute(String name,
Object value)
XXX
setMaxInactiveInterval
public void setMaxInactiveInterval(int interval)
throws IllegalStateException
Sets the minimum time this session will be kept alive by the
server when it doesn't get accessed by a client.
Note: hmmm, should an interval of -1 mean that it should live forever?
interval
- Probably seconds or -1 if never