• Spring 4 官方文档学习(十一)Web MVC 框架之Flash Attributes


    接上一篇中的重定向。

    http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-flash-attributes

    flash attributes提供了一种方式让一个请求保存attribute用于其他请求。这在重定向时很常见--例如,Post/Redirect/Get pattern。flash attributes会被临时的保存--在重定向之前,通常是保存在session中

    对于flash attributes的支持,Spring MVC有两个主要抽象。FlashMap用于hold flash attributes,FlashMapManager用于存储、获取以及管理FlashMap实例。

    Flash attribute支持总是打开的,不需要显式的启用。每个请求,都有一个"input" FlashMap -- 带有从前一个请求传来的attributes(如果有),以及一个"output" FlashMap-- 带有将要存储给下一个请求使用的attributes。两个FlashMap实例都可以在任意地方使用RequestContextUtils中的静态方法来访问。

    使用注解的controllers通常不需要直接使用FlashMap。相反,@RequestMapping method可以接受一个RedirectAttributes类型的参数,并使用其来添加用于重定向的flash attributes。通过RedirectAttributes添加的flash attributes会被自动传播到"output" FlashMap。 同样的,重定向之后,来自"input" FlashMap的attributes会被自动添加到controller的Model中,以服务目标URL。

    匹配请求到flash attributes

    flash attributes的概念存在于很多其他Web框架中,且被证明可能导致并发问题。这是因为,根据定义,flash attributes是被存储截止到下一个请求。然而,下一个请求,可能不是预期的接收者,而是另一个异步请求(例如,polling或资源请求),这种情况下,flash attributes会被过早的移除。

    为了降低这种问题的可能性,RedirectView会自动给FlashMap实例们加一个印章 -- 带有目标重定向URL的path和query parameters。默认的FlashMapManager会匹配请求和该信息 -- 在查找"input" FlashMap时。

    这不会完全消灭并发问题的可能性,但会很大程度上降低。因此,flash attributes,推荐主要在重定向场景中使用!!!

  • 相关阅读:
    HITCON Training lab14 magic heap 堆技巧unsroted bin attack
    堆技巧Unsorted Bin Attack
    2014-hack-lu-oreo 堆技巧house of spirit
    极客时间JVM虚拟机
    堆技巧 housr_of_spirit 绕过检查源码分析
    babyheap_0ctf_2017 堆技巧 fastbin-attack
    gyctf_2020_borrowstack wp
    SqlServer Where后面Case When语句的写法
    EasyUI TextBox的onkeypress事件
    SQL
  • 原文地址:https://www.cnblogs.com/larryzeal/p/6128456.html
Copyright © 2020-2023  润新知