springMVC RedirectAttributes用法
来源:互联网 发布:QQ源码 编辑:程序博客网 时间:2024/05/17 22:21
之前看书上说springMVC重定向的时候可以调用RedirectAttributes的addFlushAttribute方法向重定向后的页面传值。
但是实践之后在jsp页面并获取不到值。这是我的代码:
Controller:
@RequestMapping("/test")public String test(RedirectAttributes r){r.addFlashAttribute("msg","hello");return "/fail.jsp";}
fail.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body>${msg }</body></html>结果并获取不到值......然后百度之,找不到解决方案,去官网看RedirectAttributes的使用说明,并没有页面中如何获取的说明。
只说用到一个FlushMap实现,重定向的时候把属性暂时放在session里面的。
好吧,我估计jsp页面里面有一个flushmap,就把session里面和request里面的attributeNames全打印出来
<%
Enumeration en = request.getParameterNames();
while(en.hasMoreElements())
System.out.println(en.nextElement());
%>
输出结果:org.springframework.web.servlet.support.SessionFlashMapManager.FLASH_MAPS
就是你了,通过session.getAttribute("org.springframework.web.servlet.support.SessionFlashMapManager.FLASH_MAPS").getClass().getClassName()获取到是一个List类型的。相同的方法获取到为List<FlashMap>类型,成功了。
下面是jsp最终的代码:
<%
Enumeration en = request.getParameterNames();
while(en.hasMoreElements())
System.out.println(en.nextElement());
List<FlashMap> list =(List<FlashMap>)session.getAttribute("org.springframework.web.servlet.support.SessionFlashMapManager.FLASH_MAPS");
FlashMap fm = list.get(0);
String msg=(String)fm.get("msg");
%>
<%=msg %>
- springMVC RedirectAttributes用法
- springmvc之RedirectAttributes用法
- springmvc重定向RedirectAttributes的用法
- springMVC之RedirectAttributes
- SpringMVC之RedirectAttributes
- SpringMVC 重定向参数 RedirectAttributes
- SpringMVC 重定向参数 RedirectAttributes
- springmvc的RedirectAttributes使用方式
- SpringMVC 重定向参数 RedirectAttributes
- Spring中RedirectAttributes的用法
- Spring MVC RedirectAttributes的用法
- RedirectAttributes
- RedirectAttributes
- springMVC 请求转发和重定向(RedirectAttributes)
- springmvc中参数传递---RedirectAttributes简
- springmvc之RedirectAttributes重定向带参数设置
- SpringMVC重定向RedirectAttributes的使用
- SpringMVC使用RedirectAttributes实现错误消息处理
- 【MyBatis学习06】输入映射和输出映射
- spring配置工厂bean
- Android Studio导入项目的几种方法
- java.lang.Class.getComponentType()方法
- 【颗粒归仓】(四)代码走查--在MSBuild上集成StyleCop的配置
- springMVC RedirectAttributes用法
- iOS 加载图片选择imageNamed 方法还是 imageWithContentsOfFile?
- jQuery EasyUI-动态改变主题
- MyBatis 缓存机制深度解剖 / 自定义二级缓存
- Centos中部署WordPress无法更新问题
- HTML 参考手册 基本属性 常用标签
- 再谈强制类型转换
- python安装whl文件
- 二叉树面试(三)