接口 WebSession
The creation of a WebSession instance does not automatically start
a session thus causing the session id to be sent to the client (typically via
a cookie). A session starts implicitly when session attributes are added.
A session may also be created explicitly via start().
- 从以下版本开始:
- 2019-09-27 20:16
- 作者:
- Harry Yang
- 另请参阅:
-
方法概要
修饰符和类型方法说明Return the names Iterator.voidGenerate a new id for the session and update the underlying session storage to reflect the new id.getAttribute(String name) Returns the object bound with the specified name in this session, ornullif no object is bound under the name.String[]Return the names of all attributes.Return attributes mapReturn the time when the session was created.getId()returns this session's idReturn the last time of session access as a result of user activity such as an HTTP request.Return the maximum time after thelastAccessTimebefore a session expires.booleanhasAttribute(String name) Returntrueif the attribute identified bynameexists.booleanReturnstrueif this map contains no key-value mappings.voidInvalidate the current session and clear session storage.booleanReturntrueif the session expired aftermaxIdleTimeelapsed.booleanWhether a session with the client has been started explicitly viastart()or implicitly by adding session attributes.removeAttribute(String name) Removes the object bound with the specified name from this session.voidsave()Save the session through theSessionRepositoryas follows: If the session is new (i.e. created but never persisted), it must have been started explicitly viastart()or implicitly by adding attributes, or otherwise this method should have no effect.voidsetAttribute(String name, Object value) Binds an object to this session, using the name specified.voidsetLastAccessTime(Instant lastAccessTime) Sets the last accessed time.voidsetMaxIdleTime(Duration maxIdleTime) Configure the max amount of time that may elapse after thelastAccessTimebefore a session is considered expired.voidstart()Force the creation of a session causing the session id to be sent whensave()is called.
-
方法详细资料
-
getId
String getId()returns this session's id -
start
void start()Force the creation of a session causing the session id to be sent whensave()is called. -
isStarted
boolean isStarted() -
changeSessionId
void changeSessionId()Generate a new id for the session and update the underlying session storage to reflect the new id. After a successful callgetId()reflects the new session id. -
save
void save()Save the session through theSessionRepositoryas follows:- If the session is new (i.e. created but never persisted), it must have
been started explicitly via
start()or implicitly by adding attributes, or otherwise this method should have no effect. - If the session was retrieved through the
WebSessionStore, the implementation for this method must check whether the session wasinvalidatedand if so return an error.
Note that this method is not intended for direct use by applications. Instead it is automatically invoked just before the response is committed.
- If the session is new (i.e. created but never persisted), it must have
been started explicitly via
-
invalidate
void invalidate()Invalidate the current session and clear session storage. -
isExpired
boolean isExpired()Returntrueif the session expired aftermaxIdleTimeelapsed.Typically expiration checks should be automatically made when a session is accessed, a new
WebSessioninstance created if necessary, at the start of request processing so that applications don't have to worry about expired session by default. -
getCreationTime
Instant getCreationTime()Return the time when the session was created. -
getLastAccessTime
Instant getLastAccessTime()Return the last time of session access as a result of user activity such as an HTTP request. Together withmaxIdleTimeInSecondsthis helps to determine when a session isexpired. -
setLastAccessTime
Sets the last accessed time.- 参数:
lastAccessTime- the last accessed time
-
setMaxIdleTime
Configure the max amount of time that may elapse after thelastAccessTimebefore a session is considered expired. A negative value indicates the session should not expire. -
getMaxIdleTime
Duration getMaxIdleTime()Return the maximum time after thelastAccessTimebefore a session expires. A negative time indicates the session doesn't expire. -
setAttribute
Binds an object to this session, using the name specified. If an object of the same name is already bound to the session, the object is replaced.After this method executes, and if the new object implements
AttributeBindingListener, the container callsAttributeBindingListener.valueBound. The container then notifies anyHttpSessionAttributeListeners in the web application.If an object was already bound to this session of this name that implements
AttributeBindingListener, itsAttributeBindingListener.valueUnboundmethod is called.If the value passed in is null, this has the same effect as calling
removeAttribute().- 参数:
name- the name to which the object is bound; cannot be nullvalue- the object to be bound
-
getAttribute
Returns the object bound with the specified name in this session, ornullif no object is bound under the name.- 参数:
name- a string specifying the name of the object- 返回:
- the object with the specified name
-
removeAttribute
Removes the object bound with the specified name from this session. If the session does not have an object bound with the specified name, this method does nothing.After this method executes, and if the object implements
AttributeBindingListener, the container callsAttributeBindingListener.valueUnbound. The container then notifies anyWebSessionAttributeListeners in the web application.- 参数:
name- the name of the object to remove from this session
-
hasAttribute
Returntrueif the attribute identified bynameexists. Otherwise returnfalse.- 参数:
name- the unique attribute key
-
getAttributeNames
String[] getAttributeNames()Return the names of all attributes. -
attributeNames
Return the names Iterator.- 从以下版本开始:
- 4.0
-
hasAttributes
boolean hasAttributes()Returnstrueif this map contains no key-value mappings.- 返回:
trueif this map contains no key-value mappings- 从以下版本开始:
- 4.0
-
getAttributes
Return attributes map- 返回:
- attributes map
-