@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学习001 --环境搭建

    系统 : win cmd: cmder 链接:https://cmder.net/ 1.安装node.js 链接地址: http://cdn.npm.taobao.org/dist/node/v10. ...

  2. Ubuntu 16.04安装Fiddler抓包工具(基于Mono,且会有BUG)

    说明:Fiddler官方提供了Mono版本的,但是只有2014版本的,不是最新的,并且运行期间会有BUG,比如界面错乱卡死等等,但是勉强能代理,抓SSL的包,如果使用了要做好心理准备.将就一下还是可以 ...

  3. Excel中MATCH函数的正确使用

    Excel中MATCH函数是一个很强大的辅助函数, MATCH函数语法为:MATCH(lookup_value,lookuparray,match-type) lookup_value:表示查询的指定 ...

  4. Linux 修改终端命令提示符颜色

    相信很多人已经看厌了Linux已成不变的命令提示符的颜色,多数人要么使用默认的绿色,要么在使用PUTTY的时候设置成绿色的,不知道是否有人想到提示符可以设置成其他的颜色呢,本文就说明命令提示符变量PS ...

  5. java-组合优于继承

    组合和继承.都能实现对类的扩展. 差别例如以下表所看到的 组合 继承 has-a关系 is-a关系 执行期决定 编译期决定 不破坏封装,总体和局部松耦合 破坏封装,子类依赖父类 支持扩展,任意添加组合 ...

  6. 找中位数O(n)算法

    题目描写叙述: 给定一个未排序的整数数组,找到当中位数. 中位数是排序后数组的中间值,假设数组的个数是偶数个.则返回排序后数组的第N/2个数. 例子 给出数组[4, 5, 1, 2, 3], 返回 3 ...

  7. 分享一个基于Bootstrap的 ACE框架 入门(MVC+EF)

    基于Bootstrap3,拥有强大的功能组件以及UI组件,基本能满足后台管理系统的需求, 而且能根据不同设备适配显示,而且还有四个主题可以切换. 简单入门,源代码下载:https://github.c ...

  8. jquery全选,取消全选

    近期项目又用到了这个全选和取消全选的操作. 曾经总是自己写纯JS.如今既然知道怎么写了.那怎样用JQ写得更简洁呢.这样也能学到新的东西.假设乎百度一下果然发现了好东东.感谢OSC的iuhoay. 代码 ...

  9. 一张图理清js原型链(通过内置对象的引用关系)

    很多同学估计写了几年js也没有搞清内置对象之间的原型链关系,鄙人抽空手绘了一张简图,以作参考: 简单说明一下,上图中annonymous()函数相当于是所有函数的根(它本身也是函数),他上面提供了一些 ...

  10. What are some advantages of using Node.js over a Flask API?

    https://www.quora.com/What-are-some-advantages-of-using-Node-js-over-a-Flask-API Flask is a Python w ...