forword跳转页面的三种方式

1.使用serlvet

/**
* 使用forward跳转,传递基本类型参数到页面
* 注意:
* 1.使用servlet原生API Request作用域
*
*/
@RequestMapping("/test")
public String test(HttpServletRequest request,HttpServletResponse response){
String name = "张小三";
request.setAttribute("name",name);
return "/back/attr";
}

2.使用Model对象

/**
* 使用forward跳转,传递基本类型参数到页面
* 注意:
* 1.使用springmvc 封装好的Model对象(底层就是request作用域)
*/
@RequestMapping("/test1")
public String test1(Model model){
String name = "张小四";
model.addAttribute("name", name);
return "back/attr"; }

3.使用ModelAndView

/**
* 使用modelAndView
* 注意事项
* modelAndView对象中的数据只能被ModelAndView对象的视图获取
*/
@RequestMapping("/test2")
public ModelAndView test2(ModelAndView modelAndView){
String name = "张小五";
modelAndView.setViewName("back/attr");
modelAndView.addObject("name", name);
return modelAndView; }

当然也可以通过new 一个ModelAndView对象来实现

@RequestMapping("/test3")
public ModelAndView test3(){
String name = "张小六";
return new ModelAndView("back/attr", "name", name);
}

redirect跳转到页面

使用servlet

/**
* 使用redirect跳转 向页面传递数据
* 1.使用Servlet原生API Session ServletContext
*/ @RequestMapping("/test4")
public String test4(HttpServletRequest request,HttpSession session){
String name = "张晓霞";
session.setAttribute("name", name);
return "redirect:/back/attr.jsp";
}

使用ModelAndView

/**
* 使用redirect跳转 向页面传递数据
* 1..使用ModelAndView对象 modelAndView对象会把model中的数据以?形式拼接到地址栏后 可以使用${param.key}接受
*/
@RequestMapping("/test5")
public ModelAndView test5(){
return new ModelAndView("redirect:/back/attr.jsp","name","小张张");
}

跳转到Controller中的方法

forword跳转

redirect跳转类似

跳转到相同类中的方法:

/**
* 使用forword跳转到相同类中的某一方法
* 注意:
* 1.不需要加上类上的@RequestMapping的值
*/
@RequestMapping("/test00")
public String test00(){
return "forward:test1";
}

跳转到不同类中的方法

/**
* 使用forword跳转到不同类中的某一方法
* 注意:
* 1.需要加上类上的@RequestMapping的值:比如 :/hello
*/
@RequestMapping("/test01")
public String test01(){
return "forward:/hello/test";
}

springMvc请求的跳转和传值的更多相关文章

  1. Spring-MVC请求参数值和向页面传值

    读取请求参数值 方式一:通过HttpServletRequest req做参数 DispatcherServlet在调用处理的方法之前,利用Java反射分析方法的结构,通过分析,将req对象传过来 方 ...

  2. Android开发之Activity的创建跳转及传值

    在Android系统的江湖中有四大组件:活动(Activity), 服务(Service), 广播接收器(Broadcast Reciver)和内容提供者(Content Provider).今天所介 ...

  3. Android中实现activity的页面跳转并传值

    一个Android应用程序很少会只有一个Activity对象,如何在多个Activity之间进行跳转,而且能够互相传值是一个很基本的要求. 本次我们就讲一下,Android中页面跳转以及传值的几种方式 ...

  4. springMvc--请求的跳转和传值

    springMvc--请求的跳转和传值 目录 forword跳转页面的三种方式 1.使用serlvet 2.使用Model对象 3.使用ModelAndView redirect跳转到页面 使用ser ...

  5. H5页面跳转与传值

    页面之间的跳转经常使用a标签,使用mvc框架的都是通过访问controller的请求方法,返回请求页面.但本次开发,前端与后台完全分离,前端APP使用HBuider来开发,后台数据就无法使用mvc框架 ...

  6. springMVC请求访问的整个过程

    //以上个随笔(springMVC项目配置文件)为基础,详述springMVC请求的整个过程流向 web.xml                                            ...

  7. SpringMVC实现客户端跳转

    之前无论是/index跳转到index.jsp 还是/addProduct 跳转到showProduct.jsp,都是服务端跳转. 这一篇练习如何进行客户端跳转 @ 目录 修改IndexControl ...

  8. iOS——使用StroryBoard页面跳转及传值

    之前在网上搜iOS的页面跳转大多都是按回以前的那种xib的形式,但鄙人是使用storyboard的.这篇就只介绍利用storyboard进行页面跳转与传值. 新建页面 iOS的程序也是使用了MVC的思 ...

  9. Android课程---Activity的跳转与传值(转自网上)

    Activity跳转与传值,主要是通过Intent类来连接多个Activity,以及传递数据.   Intent是Android一个很重要的类.Intent直译是“意图”,什么是意图呢?比如你想从这个 ...

随机推荐

  1. dba诊断之IO

    --查看占用系统io较大的session   SELECT se.sid,se.serial#,pr.SPID,se.username,se.status,se.terminal,se.program ...

  2. C#基础---C#如何对Json字符串处理

    Json字符串对于做web应用的应该很熟悉,其实在很多请求我们返回的都是Json字符串.那对于C#代码如何处理Json字符串呢,.Net封装了一个类叫做JavaScriptSerializer[MSD ...

  3. [麦先生]初学Laravel框架与ThinkPHP框架的不同(2)

    在经过了一段时间的开发后,我对Laravel框架的认识又在逐步的加深,对于这个世界占有量NO.1的框架...  我想说,我已经在逐步的感受到他的恐怖之处... 一.建表--Laravel在数据库建表上 ...

  4. c++实现矩阵类矩阵行列式,伴随矩阵,逆矩阵

    //Matrix ver1.0 //只支持矩阵内部(方阵)的运算 #include<iostream> #include<math.h> using namespace std ...

  5. C++ 之 策略模式

    1  会飞的鸭子 Duck 基类,包含两个成员函数 swim() 和 display():派生类 MallardDuck,RedheadDuck 和 RubberDuck,各自重写 display() ...

  6. git config命令使用

    1. git config简介 我们知道config是配置的意思,那么git config命令就是对git进行一些配置.而配置一般都是写在配置文件里面,那么git的配置文件在哪里呢?互动一下,先问下大 ...

  7. jQuery UI常用插件使用

    一.什么是插件 ①是遵循一定接口规范编写的程序 ②是原有系统平台功能的扩展和补充 ③只能运行在规定的系统平台下,而不能单独运行 注:由于jQuery插件是基于jQuery脚本库的扩展,所以所有jQue ...

  8. 使用mxmlc在命令行编译.as代码

    在cmd命令行环境下,敲mxmlc出现 提示Error: could not find JRE和"Error: could not find Java 2 Runtime Envi 解决办法 ...

  9. C# 发送邮件,QQ企业邮箱测试成功

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...

  10. AR 不同 继承映射的问题总结

    在使用AR(Nhibernate) 做ORM时,使用类的继承体系时,它有不同的映射方式,解决的问题不同,带来的问题差异也很大. 1.所有数据 存储在一张表,不同的类使用 DiscriminatorCo ...