@Controller
public class TestController { @RequestMapping("/redirectDemo")
public String redirectDemo(RedirectAttributes attributes){
attributes.addFlashAttribute("message","error.user.login");
return "redirect:/index";
}
@RequestMapping("/index")
public String index(){
return "index";
} }

index.ftl

${message}

@RequestMapping("/redirect")
public String redirectTest(RedirectAttributes attr){
attr.addAttribute("userName", "root");
attr.addFlashAttribute("password","123456");
return "redirect:/book/getbook";
}
@RequestMapping("/getbook")
@ResponseBody
public String getBook(ModelMap map,HttpServletRequest request,@RequestParam("userName") String userName,
@RequestParam(value = "password",required = false) String password){
System.out.println("userName : "+map.get("userName"));
System.out.println("userName1 :" + request.getAttribute("userName"));
System.out.println("userName2 :" + request.getParameter("userName"));
System.out.println("userName3 : " + userName); System.out.println("password : "+map.get("password"));
System.out.println("password1 :" + request.getAttribute("password"));
System.out.println("password2 :" + request.getParameter("password"));
System.out.println("password3 : " + password); return "result";
}
请求结果
 
url : http://localhost:9019/book/getbook?userName=root
 
控制台输出
userName : null
userName1 :null
userName2 :root
userName3 : root
password : 123456
password1 :null
password2 :null
password3 : null
总结:
 
请求转发需要携带参数时
1、使用  RedirectAttributes 的 addAttribute()方法设置参数,则参数将直接拼接在转发url后面,然后可以在通过request.getParameter("userName")) 和 直接通过spring mvc配置参数映射接收到参数
2、使用 RedirectAttributes  的 addFlashAttribute()方法设置参数,则参数不会出现在转发url中,然后可以通过modelMap 取出参数
 
 
补充:
请求结果页面代码
result welcome in $!{title}; ${userName}; ${password} 
 

springMVC RedirectAttributes的更多相关文章

  1. springmvc中RedirectAttributes的作用

    RedirectAttributes在重定向的时候可以传参,不能跨站传参,因为参数是保存在服务器端

  2. SpringMVC中使用RedirectAttributes重定向传参,防止暴露参数

    RedirectAttributes是SpringMVC3.1版本之后出来的一个功能,专门用于重定向之后还能带参数跳转的. 当我从jsp页面函数中带参数到controller层方法,方法执行完毕后返回 ...

  3. springmvc中RedirectAttributes、SessionFlashMapManager的作用

    RedirectAttributes 在重定向的时候可以传参,不能跨站传参,因为参数是保存在服务器端Session中SessionFlashMapManager 是RedirectAttributes ...

  4. SpringMVC之RedirectAttributes属性

    RedirectAttributes是SpringMVC3.1版本之后出来的一个新功能,专门用于重定向之后还能带参数跳转的的工具类. 两种带参方式: redirectAttributes.addAtt ...

  5. 流程开发Activiti 与SpringMVC整合实例

    流程(Activiti) 流程是完成一系列有序动作的概述.每一个节点动作的结果将对后面的具体操作步骤产生影响.信息化系统中流程的功能完全等同于纸上办公的层级审批,尤其在oa系统中各类电子流提现较为明显 ...

  6. SpringMVC+Shiro权限管理【转】

    1.权限的简单描述 2.实例表结构及内容及POJO 3.Shiro-pom.xml 4.Shiro-web.xml 5.Shiro-MyShiro-权限认证,登录认证层 6.Shiro-applica ...

  7. springmvc(1)DispatcherServlet源码简单解析

    springmvc的简单配置 1.首先需要在web.xml中配置DispatcherServlet,这个类是springmvc的核心类,所以的操作都是由这里开始,并且大部分都是在这里面实现的,比如各种 ...

  8. SpringMVC+Shiro权限管理

    什么是权限呢?举个简单的例子: 我有一个论坛,注册的用户分为normal用户,manager用户.对论坛的帖子的操作有这些:添加,删除,更新,查看,回复我们规定:normal用户只能:添加,查看,回复 ...

  9. SpringMVC下的Shiro权限框架的使用

    SpringMVC+Shiro权限管理 博文目录 权限的简单描述 实例表结构及内容及POJO Shiro-pom.xml Shiro-web.xml Shiro-MyShiro-权限认证,登录认证层 ...

随机推荐

  1. Linux下设置swappiness参数来配置内存使用到多少才开始使用swap分区(转)

    swappiness的值的大小对如何使用swap分区是有着很大的联系的.swappiness=0的时候表示最大限度使用物理内存,然后才是swap空间,swappiness=100的时候表示积极的使用s ...

  2. linux的bc命令介绍

    bc命令是一种支持任意精度的交互执行的计算器语言.bash内置了对整数四则运算的支持,但是并不支持浮点运算,而bc命令可以很方便的进行浮点运算,当然整数运算也不再话下. 算术操作高级运算bc命令它可以 ...

  3. ASP.NET Core 奇淫技巧之动态WebApi

    一.前言 接触到动态WebApi(Dynamic Web API)这个词的已有几年,是从ABP框架里面接触到的,当时便对ABP的这个技术很好奇,后面分析了一波,也尝试过从ABP剥离一个出来作为独立组件 ...

  4. iOS中MRC和ARC混编

    1. 在targets的build phases选项下Compile Sources下选择,不使用arc编译的文件.双击它.输入 -fno-objc-arc 就可以(这个类就能够使用MRC模式) 2. ...

  5. EJB学习(三)——java.lang.ClassCastException: com.sun.proxy.$Proxy2 cannot be cast to..

    在上一篇博客介绍了怎样使用使用Eclipse+JBOSS创建第一个EJB项目,在这期间就遇到一个错误: Exception in thread "main" java.lang.C ...

  6. Xpath—解决这个问题的良药

    何为良药? 因为在XML中存在一些问题和缺陷,针对这些问题就产生了响应的解决方式.如: getElementById方法在解析XML时因为一些原因适不适合的: 首先XML中每一个元素节点不一定有id属 ...

  7. 微信小程序实战之 goods(订餐页)

    项目目录: 模拟数据: utils / data.js function getSData() { var data = [ { "name": "热销榜", ...

  8. nyoj473 A^B Problem (高速幂)

    题目473 题目信息 执行结果 pid=473" style="text-decoration:none; color:rgb(55,119,188)">本题排行 ...

  9. 一起talk C栗子吧(第一百二十一回:C语言实例--线程知识体系图)

    各位看官们.大家好,上一回中咱们说的线程属性的样例.这一回咱们说的样例是:线程知识体系图.闲话休提.言归正转. 让我们一起talk C栗子吧! 我们在前面的章回中介绍了与线程相关的知识,在今天的章回中 ...

  10. 嵌入式驱动开发之---dm8127 中sensor 驱动的改变

    #IPNC_DEVICE := DM385IPNC_DEVICE := DM812x # Values are "LOW_POWER" and "FULL_FEATURE ...