接口 WebSession

所有已知实现类:
AbstractWebSession, InMemorySessionRepository.InMemoryWebSession, MapSession

public interface WebSession
Main contract for using a server-side session that provides access to session attributes across HTTP requests.

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
另请参阅:
  • 方法概要

    修饰符和类型
    方法
    说明
    default Iterator<String>
    Return the names Iterator.
    void
    Generate a new id for the session and update the underlying session storage to reflect the new id.
    Returns the object bound with the specified name in this session, or null if no object is bound under the name.
    Return the names of all attributes.
    Return attributes map
    Return the time when the session was created.
    returns this session's id
    Return the last time of session access as a result of user activity such as an HTTP request.
    Return the maximum time after the lastAccessTime before a session expires.
    boolean
    Return true if the attribute identified by name exists.
    boolean
    Returns true if this map contains no key-value mappings.
    void
    Invalidate the current session and clear session storage.
    boolean
    Return true if the session expired after maxIdleTime elapsed.
    boolean
    Whether a session with the client has been started explicitly via start() or implicitly by adding session attributes.
    Removes the object bound with the specified name from this session.
    void
    Save the session through the SessionRepository as 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.
    void
    setAttribute(String name, Object value)
    Binds an object to this session, using the name specified.
    void
    setLastAccessTime(Instant lastAccessTime)
    Sets the last accessed time.
    void
    setMaxIdleTime(Duration maxIdleTime)
    Configure the max amount of time that may elapse after the lastAccessTime before a session is considered expired.
    void
    Force the creation of a session causing the session id to be sent when save() 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 when save() is called.
    • isStarted

      boolean isStarted()
      Whether a session with the client has been started explicitly via start() or implicitly by adding session attributes. If "false" then the session id is not sent to the client and the save() method is essentially a no-op.
    • changeSessionId

      void changeSessionId()
      Generate a new id for the session and update the underlying session storage to reflect the new id. After a successful call getId() reflects the new session id.
    • save

      void save()
      Save the session through the SessionRepository as 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 was invalidated and 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.

    • invalidate

      void invalidate()
      Invalidate the current session and clear session storage.
    • isExpired

      boolean isExpired()
      Return true if the session expired after maxIdleTime elapsed.

      Typically expiration checks should be automatically made when a session is accessed, a new WebSession instance 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 with maxIdleTimeInSeconds this helps to determine when a session is expired.
    • setLastAccessTime

      void setLastAccessTime(Instant lastAccessTime)
      Sets the last accessed time.
      参数:
      lastAccessTime - the last accessed time
    • setMaxIdleTime

      void setMaxIdleTime(Duration maxIdleTime)
      Configure the max amount of time that may elapse after the lastAccessTime before a session is considered expired. A negative value indicates the session should not expire.
    • getMaxIdleTime

      Duration getMaxIdleTime()
      Return the maximum time after the lastAccessTime before a session expires. A negative time indicates the session doesn't expire.
    • setAttribute

      void setAttribute(String name, @Nullable Object value)
      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 calls AttributeBindingListener.valueBound. The container then notifies any HttpSessionAttributeListeners in the web application.

      If an object was already bound to this session of this name that implements AttributeBindingListener, its AttributeBindingListener.valueUnbound method 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 null
      value - the object to be bound
    • getAttribute

      @Nullable Object getAttribute(String name)
      Returns the object bound with the specified name in this session, or null if no object is bound under the name.
      参数:
      name - a string specifying the name of the object
      返回:
      the object with the specified name
    • removeAttribute

      @Nullable Object removeAttribute(String name)
      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 calls AttributeBindingListener.valueUnbound . The container then notifies any WebSessionAttributeListeners in the web application.

      参数:
      name - the name of the object to remove from this session
    • hasAttribute

      boolean hasAttribute(String name)
      Return true if the attribute identified by name exists. Otherwise return false.
      参数:
      name - the unique attribute key
    • getAttributeNames

      String[] getAttributeNames()
      Return the names of all attributes.
    • attributeNames

      default Iterator<String> attributeNames()
      Return the names Iterator.
      从以下版本开始:
      4.0
    • hasAttributes

      boolean hasAttributes()
      Returns true if this map contains no key-value mappings.
      返回:
      true if this map contains no key-value mappings
      从以下版本开始:
      4.0
    • getAttributes

      Map<String,Object> getAttributes()
      Return attributes map
      返回:
      attributes map