public interface HttpSession
The handling of the Session objects is a job done by the server and servlets together.
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
getAttribute(java.lang.String name)
get the attribute value associated with the name
|
java.util.Enumeration |
getAttributeNames()
get the list of attribute names
|
long |
getCreationTime()
Gets this session's creation time in seconds since january 1st 1970.
|
java.lang.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.
|
ServletContext |
getServletContext()
Get the ServletContext to which this session belongs
|
HttpSessionContext |
getSessionContext()
Deprecated.
HttpSessionContext has been deprecated for
security reasons. |
java.lang.Object |
getValue(java.lang.String name)
Deprecated.
use
getAttribute(java.lang.String) instead |
java.lang.String[] |
getValueNames()
Deprecated.
use
getAttributeNames() instead |
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(java.lang.String name,
java.lang.Object value)
Deprecated.
Servlet API 2.2 use
instead |
void |
removeAttribute(java.lang.String name)
remove the specified attribute.
|
void |
removeValue(java.lang.String name)
Deprecated.
use
removeAttribute(java.lang.String) instead |
void |
setAttribute(java.lang.String name,
java.lang.Object value)
set the attribute value to be associated with the name.
|
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? |
long getCreationTime()
java.lang.IllegalStateException
- if the session has been invalidated.java.lang.String getId()
java.lang.IllegalStateException
- if the session has been invalidated.long getLastAccessedTime()
java.lang.IllegalStateException
- if the session has been invalidated.ServletContext getServletContext()
void setMaxInactiveInterval(int interval)
interval
- Probably seconds or -1 if neverjava.lang.IllegalStateException
- if this session has been invalidatedint getMaxInactiveInterval()
HttpSessionContext getSessionContext()
HttpSessionContext
has been deprecated for
security reasons.java.lang.IllegalStateException
- if the session has been invalidated.java.lang.Object getAttribute(java.lang.String name)
name
- the name of the attributejava.lang.IllegalStateException
- if this session has been invalidatedjava.lang.Object getValue(java.lang.String name)
getAttribute(java.lang.String)
insteadname
- the name of the item requiredjava.lang.IllegalStateException
- if the session has been invalidated.java.util.Enumeration getAttributeNames()
java.lang.IllegalStateException
- if this session has been invalidatedjava.lang.String[] getValueNames()
getAttributeNames()
insteadjava.lang.IllegalStateException
- if the session has been invalidated.void setAttribute(java.lang.String name, java.lang.Object value)
java.lang.IllegalStateException
- if this session has been invalidatedvoid putValue(java.lang.String name, java.lang.Object value)
instead
HttpSessionBindindListener
then
the valueBound()
method of the Object will be called.name
- the name of the itemvalue
- the value of the itemjava.lang.IllegalStateException
- if the session has been invalidated.void removeAttribute(java.lang.String name)
java.lang.IllegalStateException
- if this session has been invalidatedvoid removeValue(java.lang.String name)
removeAttribute(java.lang.String)
insteadHttpSessionBindindListener
then
the valueUnBound()
method of the Object will be called.name
- the name of the item.java.lang.IllegalStateException
- if the session has been invalidated.void invalidate()
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.java.lang.IllegalStateException
- if the session has been invalidated.boolean isNew()
java.lang.IllegalStateException
- if the session has been invalidated.