Spring MVC 中的 forward redirect Flash属性
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属性的更多相关文章
- Spring MVC 中的 forward 和 redirect
Spring MVC 中,我们在返回逻辑视图时,框架会通过 viewResolver 来解析得到具体的 View,然后向浏览器渲染.假设逻辑视图名为 hello,通过配置,我们配置某个 ViewRes ...
- SpringMvc(4-1)Spring MVC 中的 forward 和 redirect
Spring MVC 中,我们在返回逻辑视图时,框架会通过 viewResolver 来解析得到具体的 View,然后向浏览器渲染.通过配置,我们配置某个 ViewResolver 如下: <b ...
- SpringMvc(4-1)Spring MVC 中的 forward 和 redirect(转)
Spring MVC 中,我们在返回逻辑视图时,框架会通过 viewResolver 来解析得到具体的 View,然后向浏览器渲染.通过配置,我们配置某个 ViewResolver 如下: <b ...
- Spring MVC中forward请求转发2种方式(带参数)
Spring MVC中forward请求转发2种方式(带参数) http://www.51gjie.com/javaweb/956.html
- Spring MVC 中的基于注解的 Controller【转】
原文地址:http://my.oschina.net/abian/blog/128028 终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 H ...
- Spring MVC中基于注解的 Controller
终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 HandlerMapping 来映射出相应的 handler 并调用相应的方法以响 ...
- Spring MVC中数据绑定(转)
Spring MVC中数据绑定 比如Product有一个createTime属性,是java.util.Date类型.那么最简单的转型处理是,在SimpleFormController中覆盖initB ...
- Spring MVC 中的基于注解的 Controller(转载)
终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 HandlerMapping 来映射出相应的 handler 并调用相应的方法 ...
- Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法
Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法 在Action中方法的返回值都是字符串行,一般情况是返回某个JSP,如: return "xx" ...
随机推荐
- waffit防火墙检测
Waffit是一款Web应用防火墙检测工具,检测防火墙保护的站点是在渗透测试中非常重要的一步.如果没有对WAF进行配置,有时候可能存在漏洞.在渗透测试和风险评估中分析WAF也是非常重要的.通过编码攻击 ...
- pandas 常用清洗数据(三)排序,去重
1.排序 DataFrame 按照Index排序 Series.order()进行排序,而DataFrame则用sort或者sort_index或者sort_values 2.去重, dt = dt. ...
- centos mongodb
cd到mongodb目录下的bin文件夹,执行命令./mongo 运行如下: [root@namenode mongodb]# ./bin/mongo MongoDB shell version: 1 ...
- I/O复用之epoll
epoll 简介 epoll是为处理大批量句柄而作了改进的poll,它是在2.5.44内核中被引进的. 相关函数调用 int epoll_create(int size); 创建一个epoll的句柄. ...
- PHP 用正则获取URL的根域名
function GetUrlRoot($url){ preg_match('/[\w][\w-]*\.(?:com\.cn|com|cn|co|net|org|gov|cc|biz|info)(\/ ...
- KNN算法应用
import numpy as np# 运算符模块,这里主要用来排序 import operator import matplotlib.pylab as plt def create_dataset ...
- 与服务器同步工程(expect脚本)
先看下我实际用的例子: #!/usr/bin/expect spawn rsync -vazu ssh-src/src wayne@192.168.5.2:~/projects/ expect &qu ...
- 191. Number of 1 Bits (Int; Bit)
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...
- @ResponseBody使用须知
-------------------siwuxie095 @ResponseBody 使用须知 使用 @ResponseBody 注解映射响应体 @ResponseBody 注解可被应用于方法上,标 ...
- TZOJ 3710 修路问题(最小差值生成树kruskal或者LCT)
描述 xxx国“山头乡”有n个村子,政府准备修建乡村公路,由于地形复杂,有些乡村之间可能无法修筑公路,因此政府经过仔细的考察,终于得到了所有可能的修路费用数据.并将其公布于众,广泛征求村民的修路意见. ...