forward:转发

redirect:重定向

-- 转发比重定向快,因为重定向经过客户端,而转发并没有。

-- 重定向能够重定向到一个外部网站,但转发不行。

-- 重定向能够避免在用户重新加载页面时再次调用同样的动作。

-- Spring 3.1 以后通过 Flash 属性提供了一种供重定向传值的方法。

使用 Flash 属性,必须在 Spring MVC 配置文件中有一个 <annotation-driven /> 元素,然后必须在方法上添加一个新的参数类型 org.springframework.web.servlet.mvc.support.RedirectAttributes

@RequestMapping(value = "product_save", method = RequestMethod.POST)
public String saveProduct(ProductForm productForm, RedirectAttributes redirectAttribute){
logger.info("saveProduct called");
// no need to create and instantiate a ProductForm
// create Product
Product product = new Product();
product .setName(productForm.getName());
product.setDescription(productForm.getDescription());
try {
product.setPrice(Float.parseFloat(productForm.getPrice()));
} catch (NumberformatException e){
}
// add product
Product saveProduct = productService.add(product);
redirectAttributes.addFlashAttribute("message", "The product was successfully added.");
return "redirect:/product_view/" + saveProduct.getId();
}

Spring MVC 中的 forward redirect Flash属性的更多相关文章

  1. Spring MVC 中的 forward 和 redirect

    Spring MVC 中,我们在返回逻辑视图时,框架会通过 viewResolver 来解析得到具体的 View,然后向浏览器渲染.假设逻辑视图名为 hello,通过配置,我们配置某个 ViewRes ...

  2. SpringMvc(4-1)Spring MVC 中的 forward 和 redirect

    Spring MVC 中,我们在返回逻辑视图时,框架会通过 viewResolver 来解析得到具体的 View,然后向浏览器渲染.通过配置,我们配置某个 ViewResolver 如下: <b ...

  3. SpringMvc(4-1)Spring MVC 中的 forward 和 redirect(转)

    Spring MVC 中,我们在返回逻辑视图时,框架会通过 viewResolver 来解析得到具体的 View,然后向浏览器渲染.通过配置,我们配置某个 ViewResolver 如下: <b ...

  4. Spring MVC中forward请求转发2种方式(带参数)

    Spring MVC中forward请求转发2种方式(带参数) http://www.51gjie.com/javaweb/956.html  

  5. Spring MVC 中的基于注解的 Controller【转】

    原文地址:http://my.oschina.net/abian/blog/128028 终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 H ...

  6. Spring MVC中基于注解的 Controller

         终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 HandlerMapping 来映射出相应的 handler 并调用相应的方法以响 ...

  7. Spring MVC中数据绑定(转)

    Spring MVC中数据绑定 比如Product有一个createTime属性,是java.util.Date类型.那么最简单的转型处理是,在SimpleFormController中覆盖initB ...

  8. Spring MVC 中的基于注解的 Controller(转载)

           终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 HandlerMapping 来映射出相应的 handler 并调用相应的方法 ...

  9. Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法

    Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法 在Action中方法的返回值都是字符串行,一般情况是返回某个JSP,如: return "xx" ...

随机推荐

  1. cd-hit软件

    参考网址:https://www.jianshu.com/p/57af07b9e986 1.安装 wget https://github.com/weizhongli/cdhit/releases/d ...

  2. quast-lg

    1.官网简介 http://cab.spbu.ru/software/quast-lg/ QUAST- lg是QUAST的一个扩展,用于评估大型基因组装配(直至哺乳动物大小).QUAST- lg从5. ...

  3. Android的框架功能说明

    OkHttp网络框架 Picasso图片缓存框架 ORMLite数据库框架 GreenDao数据库框架

  4. RockerMQ介绍 及搭建双master模式

    一.RocketMQ介绍 1.1 简介 RocketMQ 是一款分布式.队列模型的消息中间件,具有以下特点: 能够保证严格的消息顺序 提供丰富的消息拉取模式 高效的订阅者水平扩展能力 实时的消息订阅机 ...

  5. 微信小程序开发——前端如何区分小程序运行环境

    前言: 之前用vue做h5项目,对于接口请求,都是根据前端访问域名来判断运行环境,然后自动适配对应的服务器地址的.这样的好处就是在开发.测试及发布上线全程都不需要手动去改接口请求地址,只要提前配置好就 ...

  6. TZOJ 3030 Courses(二分图匹配)

    描述 Consider a group of N students and P courses. Each student visits zero, one or more than one cour ...

  7. 【C】C语言中的_exit()与exit()

    _exit()和exit()主要区别是一个退出进程会清理I/O缓冲区,一个直接结束进程进入到内核中. 举例说明: #include <stdio.h> /*demo01 程序只输出 hel ...

  8. swift - 使用系统app导航

    import UIKit //1.导入框架 import MapKit class ViewController: UIViewController { lazy var geoCoder : CLG ...

  9. linux下Redis主从复制

    Redis的主从配置比起MySQL主从配置简单多了,而且Redis主从复制中一个主服务可以有多个从服务,一个从服务又可以有多个从服务. MySQL主从配置http://www.cnblogs.com/ ...

  10. 使用Nginx做转发和匹配替换

    Nginx是一个强大的服务器软件,由于处理数据内容处于第七层协议应用层的原因,所以获取的数据也比较完整: Nginx做转发: 这个很简单,vi nginx.conf(编辑nginx配置文件) 添加lo ...