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" ...
随机推荐
- JavaScript Drag处理
[JavaScript Drag处理] 在拖动目标上触发事件 (源元素): ondragstart - 用户开始拖动元素时触发 ondrag - 元素正在拖动时触发 ondragend - 用户完成元 ...
- python全栈 函数名 闭包及迭代器
1,函数名的运用 2.闭包 3.迭代器 一.函数名的运用 1.函数名的命名规范和变量是一样的 函数名其实就是变量名 (1)函数名的内存地址 例: def func(): print("ale ...
- js增减日期
参考 https://www.cnblogs.com/gmq-sh/p/5194706.html date.setDate(date.getDate() + 3);
- 【Spider】学习使用XMLFeedSpider
前面写了学习CrawlSpider遇到的问题后,今天学XMLFeedSpider又出现了启动后没爬取到数据,但又不报错的情况 经过排查,发现又是一个粗心大意的错误: class SpiderUserX ...
- BeautifulSoup中查找元素 select() 和find()区别
从html中查找元素,之前一般都用find(),查找符合条件的第一个,如下 f = open(file, 'r') # 读取文件内容content = f.read()soup= BeautifulS ...
- pta l2-1紧急救援(Dijkstra)
题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805073643683840 题意:给n个城市,m条边,每个城市 ...
- shell中参数的传递
1.命令行参数 向shell脚本传递数据的最基本方式是使用命令行参数. (1) 读取参数 读取输入的参数的变量为位置参数,位置参数通过标准数字表示, 其中$0为程序名称,$1为第一个参数,$2为第二个 ...
- 截图原理(二)——android自动化测试学习历程
接上一篇(截图原理) 视频地址:http://study.163.com/course/courseLearn.htm?courseId=712011#/learn/video?lessonId=87 ...
- mysql学习2:模糊匹配查询like,regexp,in
mysql模糊匹配查询like,regexp,in 摘要 内容比较简单,无摘要. 关键词 模糊查询 like regexp in contact 正文 下图是示例用到的数据表信息 ...
- classLoader.getResourceAsStream中文乱码
一直用一个方法安然无恙,今天在新项目中突然乱码了,原代码: ClassLoader classLoader = Thread.currentThread().getContextClassLoader ...