复习第7点-7.SpringMVC 的响应方式
1.使用ServletAPI实现转发
/*
使用HttpServletRequest对象实现请求转发
*/
@RequestMapping("/httpServletRequest")
public void method1(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("msg", "hello--httpServletRequestForward");
request.getRequestDispatcher("/index.jsp").forward(request, response);
}
2.使用 Forward 关键字实现请求转发跳转
@RequestMapping("/forward")
public String method2(HttpServletRequest request) {
request.setAttribute("msg", "hello--forward");
return "forward:/index.jsp";
}
3.使用视图解析器实现请求转发
// 访问路径之后,没有出现结果
// redirect:不能共享request范围的数据
@RequestMapping("/redirect1")
public String redirectLogin1(HttpServletRequest request) {
request.setAttribute("msg", "hello--redirectLogin1");
return "redirect:/index.jsp";
}
// 访问成功
@RequestMapping("/redirect2")
public String redirectLogin2(HttpSession session) {
session.setAttribute("msg", "hello--redirectLogin2");
return "redirect:/index.jsp";
}
redirect和forward的区别
- 地址栏的区别
forward:地址栏不发生变化
redirect:地址栏显示的是新的url - 数据共享的角度
forward:转发页面和转发到的页面可以共享request里面的数据
redirect:转发页面和转发到的页面可以共享session里面的数据
复习第7点-7.SpringMVC 的响应方式的更多相关文章
- springmvc 怎么响应json数据
springmvc 怎么响应json数据@Controller@RequestMapping("/items") class ItemsController{ @RequestM ...
- 解决ajax请求(SpringMVC后台)响应415/400/405错误
解决ajax请求(SpringMVC后台)响应415/400/405错误 后端代码 bean public class user { private String username; private ...
- 注册页面的JSON响应方式详细分析(与前端页面交互方式之一)
控制器层 需求分析: 访问路径:`/user/reg.do` //自己根据功能需求设定的请求参数:`username=xx&password=xx&&phone=xx& ...
- 0025SpringMVC的几种响应方式
本文主要涉及到一下几种响应方式: 1.返回字符串2.返回void3.返回ModelAndView4.转发关键字forward和重定向关键字redirect返回字符串5.ajax调用返回json 具体实 ...
- android学习之4种点击事件的响应方式
如题,下面就一一列出对点击事件响应的4种方式: 第一种:内部类的形式: package com.example.dail; import android.net.Uri; import android ...
- spring+springMVC集成(annotation方式)
spring+springMVC集成(annotation方式) SpringMVC+Spring4.0+Hibernate 简单的整合 MyBatis3整合Spring3.SpringMVC3
- Thinkphp5.0 的响应方式
Thinkphp5.0 的响应方式 $res = config('default_return_type'); dump($res);//默认是html //修改为json \think\Config ...
- SpringMVC的注解方式
mvc-servlet.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=&qu ...
- 一起学SpringMVC之Request方式
本文主要以一些简单的小例子,简述在SpringMVC开发过程中,经常用到的Request方面的内容,仅供学习分享使用,如有不足之处,还请指正. 概述 在客户机和服务器之间进行请求-响应时,两种最常被用 ...
- SpringMVC 请求响应流程
SpringMVC的工作原理图: SpringMVC流程 1. 用户发送请求至前端控制器DispatcherServlet. 2. DispatcherServlet收到请求调用HandlerMa ...
随机推荐
- 为测试管理正名,华为云CodeArts TestPlan的守护之道
摘要:华为云CodeArts TestPlan既有公有云版本,也有下沉到私有云的版本. 本文分享自华为云社区<为测试管理正名,华为云CodeArts TestPlan的守护之道>,作者:云 ...
- Siri Shortcut
AppDelegate.m //#pragma mark - INUIAddVoiceShortcutButtonDelegate //新添加 - (void)presentAdd ...
- python3连接postgresql/greenpulm
python3安装:pip install psycopg2github地址:https://github.com/psycopg/psycopg2文档地址:http://initd.org/psyc ...
- MySQL 嵌套子查询 with子句 from子查询 in子查询 join组合
一.适用场景和方法 (1)适用场景 考虑查询过程中是否存在以下情况: 查询某些数据时需要分组才能得到,某些数据不需要分组就能得到或者分组条件不同: 查询某些数据时需要where条件,某些列不需要whe ...
- maven打包出现Failed to execute goal xxx.plugins:maven-compiler-plugin:3.7.0:compile.......:Fatal error compiling解决方法
起初在给项目打包时出现了这个错: 网上查了很多资料,都说JDK配置不对,我检查了一下,发现明明都一样. 为了获取更详细的报错信息,我决定用命令行的打包方式来编译: cd进去要打包的这个目录,用命令行的 ...
- Coolify系列02-从0到1超详细手把手教你上手Coolify
接着上集(Coolify系列01- 从0到1超详细手把手教你上手Heroku 和 Netlify 的开源替代方案 ),此时我们已经运行成功,如果没有成功,可以参考我的Coolify系列其他文章来解决问 ...
- Lspatch使用
前言 xp模块可以使用户获得应用原本所没有的功能. 使用模块需要修改应用.对于Root用户来说,使用Lsposed是个不错的选择,也方便. 但是大多数用户没有将手机Root. 所以Lsposed的开发 ...
- 在 MBP(Apple M1 Pro)上捣鼓友善 nanoPi R5S——【一、构建 rkdeveloptool】
在种草了很多天之后,最近终于在淘宝下单了友善 nanoPi R5S. 选择友善 nanoPi R5S 有两点主要理由: 1. 自带 EMMC 存储,可以使用 RockChip 提供的 MaskRom ...
- 0源码基础学习Spring源码系列(一)——Bean注入流程
作者:京东科技 韩国凯 通过本文,读者可以0源码基础的初步学习spring源码,并能够举一反三从此进入源码世界的大米! 由于是第一次阅读源码,文章之中难免存在一些问题,还望包涵指正! 一. @Auto ...
- Nginx02 Nginx的的目录结构、基本工作原理、基本配置文件介绍
1 Nginx目录结构 1.1 简要介绍 [root@localhost ~]# tree /usr/local/nginx /usr/local/nginx ├── client_body_temp ...