org.apache.struts2.dispatcher

## Class SessionMap

- java.lang.Object
- - java.util.AbstractMap<String,Object>
  - - org.apache.struts2.dispatcher.SessionMap

- All Implemented Interfaces:
    Serializable, Map<String,Object>

      public class SessionMap
      extends AbstractMap<String,Object>
      implements Serializable

  A simple implementation of the `Map` interface to handle a collection of HTTP session attributes. The `entrySet()` method enumerates over all session attributes and creates a Set of entries. Note, this will occur lazily - only when the entry set is asked for.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class java.util.AbstractMap

      `AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>`

    - ### Nested classes/interfaces inherited from interface java.util.Map

      `Map.Entry<K,V>`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Set<Map.Entry<String,Object>>` | `entries`
    `protected javax.servlet.http.HttpServletRequest` | `request`
    `protected javax.servlet.http.HttpSession` | `session`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SessionMap(javax.servlet.http.HttpServletRequest request)` Creates a new session map given a http servlet request.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Removes all attributes from the session as well as clears entries in this map.
    `boolean` | `containsKey(Object key)` Checks if the specified session attribute with the given key exists.
    `Set<Map.Entry<String,Object>>` | `entrySet()` Returns a Set of attributes from the http session.
    `Object` | `get(Object key)` Returns the session attribute associated with the given key or `null` if it doesn't exist.
    `void` | `invalidate()` Invalidate the http session.
    `Object` | `put(String key, Object value)` Saves an attribute in the session.
    `Object` | `remove(Object key)` Removes the specified session attribute.

    - ### Methods inherited from class java.util.AbstractMap

      `clone, containsValue, equals, hashCode, isEmpty, keySet, putAll, size, toString, values`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.Map

      `compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll`

- - ### Field Detail

    - #### session

          protected javax.servlet.http.HttpSession session

    - #### entries

          protected Set<Map.Entry<String,Object>> entries

    - #### request

          protected javax.servlet.http.HttpServletRequest request

  - ### Constructor Detail

    - #### SessionMap

          public SessionMap(javax.servlet.http.HttpServletRequest request)

      Creates a new session map given a http servlet request. Note, the enumeration of request attributes will occur when the map entries are asked for.
      Parameters:
        `request` - the http servlet request object.

  - ### Method Detail

    - #### invalidate

          public void invalidate()

      Invalidate the http session.

    - #### clear

          public void clear()

      Removes all attributes from the session as well as clears entries in this map.
      Specified by:
        `clear` in interface `Map<String,Object>`
      Overrides:
        `clear` in class `AbstractMap<String,Object>`

    - #### entrySet

          public Set<Map.Entry<String,Object>> entrySet()

      Returns a Set of attributes from the http session.
      Specified by:
        `entrySet` in interface `Map<String,Object>`
      Specified by:
        `entrySet` in class `AbstractMap<String,Object>`
      Returns:
        a Set of attributes from the http session.

    - #### get

          public Object get(Object key)

      Returns the session attribute associated with the given key or `null` if it doesn't exist. Note: Must use the same signature as `AbstractMap.get(java.lang.Object)` to ensure the expected specialized behaviour is performed here (and not the generic ancestor behaviour).
      Specified by:
        `get` in interface `Map<String,Object>`
      Overrides:
        `get` in class `AbstractMap<String,Object>`
      Parameters:
        `key` - the name of the session attribute.
      Returns:
        the session attribute or `null` if it doesn't exist.

    - #### put

          public Object put(String key,
                            Object value)

      Saves an attribute in the session.
      Specified by:
        `put` in interface `Map<String,Object>`
      Overrides:
        `put` in class `AbstractMap<String,Object>`
      Parameters:
        `key` - the name of the session attribute.
        `value` - the value to set.
      Returns:
        the object that was just set.

    - #### remove

          public Object remove(Object key)

      Removes the specified session attribute. Note: Must use the same signature as `AbstractMap.remove(java.lang.Object)` to ensure the expected specialized behaviour is performed here (and not the generic ancestor behaviour).
      Specified by:
        `remove` in interface `Map<String,Object>`
      Overrides:
        `remove` in class `AbstractMap<String,Object>`
      Parameters:
        `key` - the name of the attribute to remove.
      Returns:
        the value that was removed or `null` if the value was not found (and hence, not removed).

    - #### containsKey

          public boolean containsKey(Object key)

      Checks if the specified session attribute with the given key exists. Note: Must use the same signature as `AbstractMap.containsKey(java.lang.Object)` to ensure the expected specialized behaviour is performed here (and not the generic ancestor behaviour).
      Specified by:
        `containsKey` in interface `Map<String,Object>`
      Overrides:
        `containsKey` in class `AbstractMap<String,Object>`
      Parameters:
        `key` - the name of the session attribute.
      Returns:
        `true` if the session attribute exits or `false` if it doesn't exist.

Copyright © 2000–2024 Apache Software Foundation. All rights reserved.