springMVC----结果跳转方式
来源:互联网 发布:apache 错误日志 编辑:程序博客网 时间:2024/06/05 06:51
1.设置ModelAndView对象
根据View的名称,和视图解析器,跳转到指定的页面。页面:视图解析器的前缀+view name +视图解析器的后缀名
跳转方式:转发
@RequestMapping("/hello.do") public ModelAndView show(HttpServletRequest request, HttpServletResponse response) { ModelAndView mv = new ModelAndView(); mv.addObject("msg","hello hhh"); mv.setViewName("hello"); return mv; }
2.通过Servlet API实现
这种方式不需要配置视图解析器。
通过HttpServletResponse实现
方法一
跳转方式:转发
@RequestMapping("/hello1.do") public void show2(HttpServletRequest request, HttpServletResponse response) throws IOException { response.getWriter().println("hello HttpServlet API"); }
方法二:
跳转方式:重定向
@RequestMapping("/hello1.do") public void show2(HttpServletRequest request, HttpServletResponse response) throws IOException { response.sendRedirect("index.jsp"); }
通过HttpServletRequest实现
跳转方式:转发@RequestMapping("/hello1.do") public void show2(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { request.setAttribute("msg","request"); request.getRequestDispatcher("index.jsp").forward(request,response); }
3.通过springMVC实现转发和重定向-----没有视图解析器
转发
方法一:
跳转方式:转发
@RequestMapping("/hello2.do") public String show3() { return "index.jsp"; }
方法二:
跳转方式:转发
@RequestMapping("/hello2.do") public String show3() { return "forward:index.jsp"; }
重定向
跳转方式:重定向
<pre name="code" class="plain">@RequestMapping("/hello2.do") public String show3() { return "redirect:index.jsp"; }
4.通过springMVC实现转发和重定向-----有视图解析器
转发:
@RequestMapping("/hello2.do") public String show3() { return "hello"; }注意:重定向“redirect:index.jsp”不需要视图解析器
0 0
- springMVC----结果跳转方式
- SpringMVC 跳转结果的方式.练习笔记
- SpringMVC 2(跳转结果的方式:转发、重定向)
- 结果跳转方式
- 结果跳转方式
- struts2结果处理方式(结果跳转方式)
- 迟到的总结(二)--springmvc的系统学习之跳转结果的方式
- Spring MVC 结果跳转方式
- Spring MVC结果跳转方式
- spring mvc 结果跳转方式
- Spring MVC结果跳转方式
- Spring MVC跳转结果的方式
- Spring MVC跳转结果的方式
- 第三讲 跳转结果的方式
- struts2返回结果的跳转方式
- Struts2学习(四)【结果跳转方式】
- springMVC 几种页面跳转方式
- springMVC学习笔记(四) ---- 跳转方式
- xgboost 在 win7 下安装
- 第三章html上机练习1老师发的答案
- 欢迎使用CSDN-markdown编辑器
- Restarting rabbitmq-server: RabbitMQ is not running
- iOS开发常用代码块(-)
- springMVC----结果跳转方式
- 数字图像处理入门(一)-基本概念
- java反射最简单最本质的一段代码
- 教你如何使用session
- jquery 对ajax追加元素无法绑定的问题
- Android 动态加载so
- 基于VHDL语言的几种消抖电路的设计
- WPF用户控件入门
- 各种知识点的看法感悟1