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的区别
  1. 地址栏的区别

    forward:地址栏不发生变化

    redirect:地址栏显示的是新的url
  2. 数据共享的角度

    forward:转发页面和转发到的页面可以共享request里面的数据

    redirect:转发页面和转发到的页面可以共享session里面的数据

最新文章

  1. SharePoint 2013 JavaScript API 记录
  2. Ubuntu下matlab快捷键设置
  3. 你的联动够快够小吗——基于Telerik(ASP.NET平台)
  4. JAVA之关于super的用法
  5. 使用powerdesigner 画图的详细说明
  6. vs默认的app.config是哪个?
  7. php文件格式数组
  8. php入门微理解
  9. Jasmine基础语法
  10. Bean复制
  11. 手机自动化测试:Appium源码分析之跟踪代码分析七
  12. objc[20556]:Class JavaLaunchHelper is implemented in both xxx 警告处理
  13. 705. New Distinct Substrings spoj(后缀数组求所有不同子串)
  14. (三)surging 微服务框架使用系列之我的第一个服务(审计日志)
  15. 看eShopOnContainers学一个EventBus
  16. [BZOJ1061] [Noi2008] 志愿者招募 (费用流)
  17. 剑指offer前6题
  18. 基于Centos搭建Python Web 环境搭建教程
  19. MATLAB 的输入输出命令
  20. asp.net 浏览器下载文件的四种方式

热门文章

  1. [LeetCode]至少是其他数字两倍的最大数
  2. Gitlab配置ssh_key
  3. 【分析笔记】全志平台 gpio_wdt 驱动应用和 stack crash 解决
  4. 我们从 CircleCI 安全事件获得的3个经验教训
  5. MD5在Python中的简单使用
  6. spring-security 解决
  7. 在执行npm install执行报错node-sass
  8. WinRAR的 安装与下载
  9. MySQL 常用函数一览
  10. STM32F1库函数初始化系列:DMA—ADC采集