@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. Vue基础学习

    使用vue-cli构建初始化vue项目 vue init webpack myfirst 项目截图:(开发工具:webStorm) 主要练习了vue的基本指令:v-bind.v-if.v-show.v ...

  2. makefile的语法及写法(二)

     3 Makefile书写规则 -------------------------------------------------------------------------------- 规则包 ...

  3. RHEL 启动系统及故障排除

    一:Linux的启动过程: 开机加电自检->MBR引导(boot loader占446字节,分区列表64字节,magic占2字节)-->grub菜单(MBR是grub的第一个字段,第二个字 ...

  4. composer-安装插件包

    上一步完成后,选定国内镜像地址,以为下载插件包做准备 https://pkg.phpcomposer.com/ 安装完componser后使用下面这条命令即可(设置国内镜像地址): composer ...

  5. Android 使用 DownloadManager 管理系统下载任务的方法

    在红黑联盟上看到的.这几天一直考虑做一个Notification 的带下载功能的自己定义通知.但没搞出来.无意中在论坛看到这个.先Mark,明天试试. 从Android 2.3(API level 9 ...

  6. Highcharts报表——让你的网页上图表画的飞起

    Highcharts是一款纯javascript编写的图表库,能够很简单便捷的在Web网站或Web应用中添加交互性的图表,Highcharts目前支持直线图.曲线图.面积图.柱状图.饼图.散点图等多达 ...

  7. C++ 虚函数与纯虚函数 浅析

    [摘要] 在虚函数与纯虚函数的学习中.要求理解虚函数与纯虚函数的定义,了解虚函数与纯虚函数在实例化上的差异.掌握两者在实现上的必要性.熟悉纯虚函数在子类与孙类的函数类型.本文即针对上述问题展开阐述. ...

  8. [学习笔记]渗透测试metasploit

    1.渗透成功后,在meterpreter命令行,需要使用如下命令切换当前目录.更多信息,可以参考: meterpreter > pwd C:\ meterpreter > cd /&quo ...

  9. 2016/2/26 jQuery的技术 1,安装 2,语法选择器$ 事件触发 3,常用jQuery函数

    在<网页制作Dreamweaver(悬浮动态分层导航)>中,运用到了jQuery的技术,轻松实现了菜单的下拉.显示.隐藏的效果,不必再用样式表一点点地修改,省去了很多麻烦,那么jQuery ...

  10. 再谈HBase八大应用场景

    HBase概述 HBase是一个分布式存储.数据库引擎,可以支持千万的QPS.PB级别的存储,这些都已经在生产环境验证,并且在广大的公司已经验证.特别是阿里.小米.京东.滴滴内部都有数千.上万台的HB ...