SpringMVC开发中两种页面跳转方式

 时间:2024-11-08 08:17:57

Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面。Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块。使用 Spring 可插入的 MVC 架构,从而在使用Spring进行WEB开发时,可以选择使用Spring的SpringMVC框架或集成其他MVC开发框架,如Struts1(现在一般不用),Struts2等。

工具/原料

电脑

SpringMvc

第一种:通过注解的方式进行跳转

1、第一种方法:通过HttpServletResponse的API直接输出步骤: 1.控制层:controller类的编写@Controllerpublic class RequestController{@RequestMapping("/request") //映射地址注入 public void handleRequest(HttpServletRequest rq, HttpServletResponse rp) throws Exception { rp.getWriter().println("request"); }

SpringMVC开发中两种页面跳转方式

3、 3.dispatcher-servlet.xml文件的编写争犸禀淫<beans xmlns="http://www.springframework.org/s艘早祓胂chema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!--扫描指定包下所有的注解的类--> <context:component-scan base-package="com.jsu.mvc"/></beans>

SpringMVC开发中两种页面跳转方式

5、第三种:使用HttpServletRequest 转发 @RequestMapping("/request") public void handleRequest(HttpServletRequest rq, HttpServletResponse rp) throws Exception { req.setAttribute("属性名","属性值"); //赋值 req.getRequestDispatcher(url).forward(rq,rp); //跳转 }

SpringMVC开发中两种页面跳转方式

2、第二种:使用modelview,它不需要配置视图解析器,但是不能指定跳转页面1.控制层controller的编写@RequestMapping("/modelmap")public String modelHello(String A,ModelMap B){ map.addAttribute("A",B); // 通过ModelMap键值对的方式设置传值 System.out.println(B); return "url";}

SpringMVC开发中两种页面跳转方式
  • js 判断是否为火狐浏览器
  • jquery如何选择所有为空的input标签
  • php 根据value获取key
  • 如何获得jsp动态生成的div的值
  • Linux下安装SQL Server 2016方法
  • 热门搜索
    篮球怎么过人 新年贺卡怎么做 卧蚕笔怎么用 肛门痒痒怎么回事 朋友的英文怎么写 房屋过户费怎么算 口袋妖怪金手指怎么用 茯苓粉怎么吃 游戏补丁怎么用 舌尖麻是怎么回事