@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. ffm算法

    www.csie.ntu.edu.tw/~cjlin/papers/ffm.pdf  读书笔记 The effect of feature conjunctions(组合特征) is difficul ...

  2. 怎样扩展EasyUI在页面中马上显示选中的本地图片

    在编写前台页面的时候,有时须要将选中的图片夹杂着其它信息一起上传到服务端,在选着本地图片的时候,为了获得更好的效果,须要将该图片显示在页面上. 最初思路有两个.详细例如以下: 1.获取选中文件的二进制 ...

  3. bug集合及其解决方法

    点击查看原文 1. java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 1 column 27 ...

  4. 深度学习笔记之基于R-CNN的物体检测

    不多说,直接上干货! 基于R-CNN的物体检测 原文地址:http://blog.csdn.net/hjimce/article/details/50187029 作者:hjimce 一.相关理论 本 ...

  5. The type java.lang.reflect.AnnotatedElement cannot be resolved. It is indirectly referenced from required .class files

    我这个错误发生于导入项目的时候..我发现主要是jdk版本的问题.切换一下jdk.直接红叉消失就可以了.....jdk版本一致性还是很重要的

  6. IDEA-Maven的环境配置及使用

    一.Maven的下载 IDEA的往期下载地址:https://www.jetbrains.com/ 1.点击进入 1.往期的下载地址:http://www.apache.org/ 操作步骤:我们点击进 ...

  7. URL传参中文乱码的一种解决方法

    中文乱码是由于,发送和接收方使用的编码解码格式不一致导致,以下是关于url传参解决中文乱码的一种方法,最后根据各种编码格式尝试解码,发现正确的解码格式 string strQueryString = ...

  8. redis缓存数据库的详解

    1,什么是redis? Redis是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库 Redis与其他key-value缓存产品有以下三个特点: Redis支持数据的持久化,可以 ...

  9. java8--IO(java疯狂讲义3复习笔记)

    产生文件 File file = new File("abc.txt"); if(!file.exists()){ System.out.println(file.exists() ...

  10. qemu所支持的网卡

    1 命令 -net nic 创建一个network interface card,即创建一个网卡,默认是e1000网卡. 2 qemu所支持的网卡类型 2.1 rtl8139 Realtek 10/1 ...