[学习笔记]基于注解的spring3.0.x MVC学习笔记(六)
来源:互联网 发布:mac怎么关闭隐藏文件 编辑:程序博客网 时间:2024/05/16 06:28
近期心情不太好,想起当初有些事情,继续springmvc的返回类型中带有redirect方式的使用,使用redirect方式返回跟有3种方式首先介绍第一种,代码如下:
1: @RequestMapping("/redirect")
2: public String testRedirect(ModelMap map){
3: // Map<String,Object> map = new HashMap<String, Object>();
4: map.put("testdata", "hello world!");
5: return "redirect:redirect.jsp";
6: }
使用redirect后他不会对modelmap中的数据进行调用request.setAttribute而采用带参数的形式进行传值,如下图:
再页面中调用request.getParameter("testdata")后得到以下结果:
jsp中的代码如下:
1: <%@ page language="java" contentType="text/html; charset=GB18030"
2: pageEncoding="GB18030"%>
3: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4: <html>
5: <head>
6: <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
7: <title>跳转过来的jsp</title>
8: </head>
9: <body>
10: ${testdata}
11: :
12: <%=request.getParameter("testdata")+"----" %>
13: </body>
14: </html>
事实证明使用了redirect后就变成了带参传值.
另外一种则是可以返回一个链接代码如下:
片段代码1:
1: @RequestMapping(value="/redirect",method=RequestMethod.GET)
2: public String testRedirect(ModelMap map){
3: // Map<String,Object> map = new HashMap<String, Object>();
4: map.put("testdata", "redirect:hello world!");
5: return "redirect:forward";
6: }
片段代码2:
1: @RequestMapping("/forward")
2: public String testForword(ModelMap map){
3: // Map<String,Object> map = new HashMap<String, Object>();
4: map.put("testdata", "forward to:hello world!");
5: return "forward:collection1";
6: }
片段代码3
1: @RequestMapping("/collection1")
2: public Collection collection1() {
3: logger.info("collection is runing1");
4: List toys = new ArrayList();
5: toys.add("gg5555555");
6: toys.add(new UserBean(1, "a", "b"));
7: toys.add(new UserBean(2, "PSP", "2100"));
8:
9: return toys;
10: }
在浏览器上运行/redirect得到结果如下:
很明显运行/redirect跳转到forward中然后forward中又引用了collection1所以才变成这样.
最终一种则是跳转到外部链接:代码如下:
1: @RequestMapping(value="/redirect",method=RequestMethod.GET)
2: public String testRedirect(ModelMap map){
3: // Map<String,Object> map = new HashMap<String, Object>();
4: map.put("testdata", "redirect:hello world!");
5: return "redirect:http://blog.163.com/edwardlauxh";
6: }
可以直接跳转到外部链接中,跳转到外部链接,在modelmap中所保存的值也会一直带过去所对应的网站.
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(六)
- 基于注解的spring3.0.x MVC学习笔记(二)
- 基于注解的spring3.0.x MVC学习笔记(一)
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(八)
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(二)
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(三)
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(四)
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(五)
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(七)
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(八)
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(九)
- 基于spring source tools suite注解的spring3.0.x MVC学习笔记(一)
- 基于spring source tools suite注解的spring3.0.x MVC学习笔记(二)
- 基于注解的spring 3.0.x MVC学习笔记(一)
- Spring3.X学习笔记3-基于注解和基于Java类的配置
- 基于annotation注解的Spring3 MVC之一 HelloWorld 例子学习笔记
- 基于annotation注解的Spring3 MVC Form Handling Example之二表单提交学习笔记
- 基于annotation注解的Spring3 MVC Page Redirection Example之三页面重定向学习笔记
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(三)
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(四)
- 369. Reading enrichs the mind. 开卷有益
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(五)
- 2012年的感悟
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(六)
- Java学习笔记(异常处理)
- winform缩放时,控制控件的比例
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(七)
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(八)
- [学习笔记]基于注解的spring3.0.x MVC学习笔记(九)
- Android的数据存储---可供选择的存储方案(三)
- GCC 编译优化选项
- Qt中字符串截取