org.springframework.web.servlet

Class FlashMap

  • java.lang.Object
    • java.util.AbstractMap<K,V>
      • java.util.HashMap<java.lang.String,java.lang.Object>
        • org.springframework.web.servlet.FlashMap
  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<FlashMap>, java.util.Map<java.lang.String,java.lang.Object>


    public final class FlashMap
    extends java.util.HashMap<java.lang.String,java.lang.Object>
    implements java.lang.Comparable<FlashMap>
    A FlashMap provides a way for one request to store attributes intended for use in another. This is most commonly needed when redirecting from one URL to another -- e.g. the Post/Redirect/Get pattern. A FlashMap is saved before the redirect (typically in the session) and is made available after the redirect and removed immediately.

    A FlashMap can be set up with a request path and request parameters to help identify the target request. Without this information, a FlashMap is made available to the next request, which may or may not be the intended recipient. On a redirect, the target URL is known and a FlashMap can be updated with that information. This is done automatically when the org.springframework.web.servlet.view.RedirectView is used.

    Note: annotated controllers will usually not use FlashMap directly. See org.springframework.web.servlet.mvc.support.RedirectAttributes for an overview of using flash attributes in annotated controllers.

    Since:
    3.1
    Author:
    Rossen Stoyanchev
    See Also:
    FlashMapManager, Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K,V>
    • Constructor Summary

      Constructors 
      Constructor and Description
      FlashMap() 
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      FlashMap addTargetRequestParam(java.lang.String name, java.lang.String value)
      Provide a request parameter identifying the request for this FlashMap.
      FlashMap addTargetRequestParams(MultiValueMap<java.lang.String,java.lang.String> params)
      Provide request parameters identifying the request for this FlashMap.
      int compareTo(FlashMap other)
      Compare two FlashMaps and prefer the one that specifies a target URL path or has more target URL parameters.
      boolean equals(java.lang.Object other) 
      long getExpirationTime()
      Return the expiration time for the FlashMap or -1 if the expiration period has not started.
      MultiValueMap<java.lang.String,java.lang.String> getTargetRequestParams()
      Return the parameters identifying the target request, or an empty map.
      java.lang.String getTargetRequestPath()
      Return the target URL path (or null if none specified).
      int hashCode() 
      boolean isExpired()
      Return whether this instance has expired depending on the amount of elapsed time since the call to startExpirationPeriod(int).
      void setExpirationTime(long expirationTime)
      Set the expiration time for the FlashMap.
      void setTargetRequestPath(java.lang.String path)
      Provide a URL path to help identify the target request for this FlashMap.
      void startExpirationPeriod(int timeToLive)
      Start the expiration period for this instance.
      java.lang.String toString() 
      • Methods inherited from class java.util.HashMap

        clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • FlashMap

        public FlashMap()
    • Method Detail

      • setTargetRequestPath

        public void setTargetRequestPath(@Nullable
                                         java.lang.String path)
        Provide a URL path to help identify the target request for this FlashMap.

        The path may be absolute (e.g. "/application/resource") or relative to the current request (e.g. "../resource").

      • getTargetRequestPath

        @Nullable
        public java.lang.String getTargetRequestPath()
        Return the target URL path (or null if none specified).
      • addTargetRequestParams

        public FlashMap addTargetRequestParams(@Nullable
                                               MultiValueMap<java.lang.String,java.lang.String> params)
        Provide request parameters identifying the request for this FlashMap.
        Parameters:
        params - a Map with the names and values of expected parameters
      • addTargetRequestParam

        public FlashMap addTargetRequestParam(java.lang.String name,
                                              java.lang.String value)
        Provide a request parameter identifying the request for this FlashMap.
        Parameters:
        name - the expected parameter name (skipped if empty)
        value - the expected value (skipped if empty)
      • getTargetRequestParams

        public MultiValueMap<java.lang.String,java.lang.String> getTargetRequestParams()
        Return the parameters identifying the target request, or an empty map.
      • startExpirationPeriod

        public void startExpirationPeriod(int timeToLive)
        Start the expiration period for this instance.
        Parameters:
        timeToLive - the number of seconds before expiration
      • setExpirationTime

        public void setExpirationTime(long expirationTime)
        Set the expiration time for the FlashMap. This is provided for serialization purposes but can also be used instead startExpirationPeriod(int).
        Since:
        4.2
      • getExpirationTime

        public long getExpirationTime()
        Return the expiration time for the FlashMap or -1 if the expiration period has not started.
        Since:
        4.2
      • isExpired

        public boolean isExpired()
        Return whether this instance has expired depending on the amount of elapsed time since the call to startExpirationPeriod(int).
      • compareTo

        public int compareTo(FlashMap other)
        Compare two FlashMaps and prefer the one that specifies a target URL path or has more target URL parameters. Before comparing FlashMap instances ensure that they match a given request.
        Specified by:
        compareTo in interface java.lang.Comparable<FlashMap>
      • equals

        public boolean equals(java.lang.Object other)
        Specified by:
        equals in interface java.util.Map<java.lang.String,java.lang.Object>
        Overrides:
        equals in class java.util.AbstractMap<java.lang.String,java.lang.Object>
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map<java.lang.String,java.lang.Object>
        Overrides:
        hashCode in class java.util.AbstractMap<java.lang.String,java.lang.Object>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.AbstractMap<java.lang.String,java.lang.Object>