@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. Spring MVC的Hello World例子

    以下内容引用自http://wiki.jikexueyuan.com/project/spring/mvc-framework/spring-mvc-hello-world-example.html: ...

  2. Win7 SP1 安装SQL Server 2012时提示“此计算机上的操作系统不符合 SQL Server 2012的最低要求”

  3. [教程]Delphi 中三种回调函数形式解析

    Delphi 支持三种形式的回调函数 全局函数这种方式几乎是所有的语言都支持的,类的静态函数也可以归为此类,它保存的只是一个函数的代码起始地址指针( Pointer ).在 Delphi 中声明一般为 ...

  4. CEF3研究(一)

    一.基本概览 C++ WrapperC++Wrapper(包装类)就是将C结构包装C++类. 这是C/C++API转换层通过translator tool自动产生的. 进程     CEF3用多进程运 ...

  5. 磁盘显示为GPT(保护分区)

    问题描述:PE进入系统,在计算机管理里面磁盘显示为GPT(保护分区).此时硬盘是不能重新分区或者格式化的. 解决思路:低版本的WIndows(PE)是不支持GPT分区的,我们需要使用系统自带的Disk ...

  6. Spark SQL 源代码分析之Physical Plan 到 RDD的详细实现

    /** Spark SQL源代码分析系列文章*/ 接上一篇文章Spark SQL Catalyst源代码分析之Physical Plan.本文将介绍Physical Plan的toRDD的详细实现细节 ...

  7. ASO--简单了解

    ASO是“应用商店优化”的简称.ASO(App Search Optimization)就是提升你APP在各类APP应用商店/市场排行榜和搜索结果排名的过程. 类似普通网站针对搜索引擎的优化,即SEO ...

  8. python3 base64模块代码分析

    #! /usr/bin/env python3 """Base16, Base32, Base64 (RFC 3548), Base85 and Ascii85 data ...

  9. mac 使用命令行,对远程服务器进行文件更新

    目的:更新服务器文件A 1.远程传输文件 A.zip 在本地A文件的父级文件夹下执行 scp ./A.zip 远程服务器用户名@远程服务器IP:/要放置的文件夹目录/ 然后要输入服务器登陆密码,进行文 ...

  10. .gitignore 使用入门

    .gitignore /doc/ 过滤整个文件夹. *.zip 过滤所有.zip文件. /doc/info.txt 过滤某个具体的文件. 这样,push的时候,就不会上传了,git仓库中就没有了. 假 ...