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. 前端三大框架之一React入门教程

    相信大家对框架这个词都很熟悉吧,我一直喜欢js原生来开发,但是目前都要求工作效率,所有使用框架或者是库会使我们开发更加方便和快速,甚至一个人干十个人的活.. 框架优点: 1.方便开发.快速写功能 2. ...

  2. linux suse 同步时间

    ntpdate 210.72.145.44 ip为中国(国家授时中心)

  3. spring boot 中使用 Redis 与 Log

    spring boot + mybatis + redis 配置 1.application.yml #配置访问的URLserver: servlet-path: /web port: spring: ...

  4. 分布式监控系统Zabbix-3.0.3-完整安装记录

    由于采用sendmail发送邮件,常常会被认为是垃圾邮件被拒,所以不推荐这种方式!这里,针对zabbix报警信息的发送,可以采用下面两种方式中的任意一种:1)利用sendEmail程序来发送报警邮件. ...

  5. jsp页面之初体验

    最近在学jsp 在web.xml页面中学到了如何让一个页面第一个启动

  6. 100. Same Tree (Tree;DFS)

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  7. unity农场模拟经营游戏源码

    下载地址: https://item.taobao.com/item.htm?spm=a1z10.5-c-s.w4002-12305352547.10.25ca3c4eWAibvf&id=56 ...

  8. 如何禁止chrome自动跳转https

    请在chrome的地址栏输入: chrome://net-internals/#hsts 在打开的页面中, Delete domain 栏的输入框中输入:xx.xx.com(注意这里是二级域名),然后 ...

  9. HDU 4027 Can you answer these queries? (线段树区间修改查询)

    描述 A lot of battleships of evil are arranged in a line before the battle. Our commander decides to u ...

  10. Centos和Redhat的区别与联系

    CentOS的简介 CentOS是Community ENTerprise Operating System的简称,我们有很多人叫它社区企业操作系统,不管你怎么叫它,它都是Linux操作系统的一个发行 ...