FlashAttribute,为Spring MVC 3.1版本加的特性,Flash属性,它能解决一个长久以来缺少解决的问题,一个POST/Redirect/GET模式问题
使用方法
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.mvc.support.RedirectAttributes; @Controller @RequestMapping("/redirect") public class RedirectTesController { /** * redirect * * @param attributes * @return */ @RequestMapping("/test") public String test(RedirectAttributes attributes) { attributes.addFlashAttribute("name", "张三"); return "redirect:/redirect/testShow"; } }
testShow.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html > <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>spring mvc redirect</title> </head> <body> name is : ${name} </body> </html>
页面显示