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" ...
随机推荐
- svn:Cannot negotiate authentication mechanism
解决方案:在eclipse->window->preference->team->svn中将svn接口设定为svnkit.
- mySQL遇到的问题
学习mySQL遇到以下错误. 仔细检查才发现,是字段不一样. 所以插入数据,应该一一对应.
- NBU 还原LINUX ORACLE 数据库(EHR)
一.E-HR数据库(全备)恢复 目录 一.E-HR数据库(全备)恢复... 1 1. 使用bplist 命令读取备份文件... 1 2. 启动到nomount状态... 2 3. 利用rman还原控制 ...
- sql数据库之多库查询
连接到数据库服务器gwsps07上,打开查询分析器,如何获取gwrenshi数据库中的数据? 查询语句如下: select * from GWRENSHI.CGC.dbo.PERempms(serve ...
- 830. Positions of Large Groups
In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...
- 【OpenGL】纹理(Texture)
纹理是一个2D图片(也有1D和3D),它用来添加物体的细节:这就像有一张绘有砖块的图片贴到你的3D的房子上,你的房子看起来就有了一个砖墙.因为我们可以在一张图片上插入足够多的细节,这样物体就会拥有很多 ...
- pta l2-5(集合相似度)
题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805070149828608 题意:求两个集合的相同的不同元素的 ...
- Android Studio连接真机调试
1.安装配置Android studio2.2 2.下载手机驱动或者安装手机助手(360手机助手) 3.用手机助手连接用于调试的手机 注意手机要开启开发者模式->允许USB调试 4.查看手机连接 ...
- TableViewCell去除选中效果
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableV ...
- DMZ原理与应用
DMZ是英文“demilitarized zone”的缩写,中文名称为“隔离区”,“非军事化区”.它是为了解决安装防火墙后外部网络不能访问内部网络服务器的问题,而设立的一个非安全系统与安全系统之间的缓 ...