1.配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <!-- 前端控制器
/=默认的url-pattern
/a/b/c /a /a/d/c
/a/d
/a
/
*注意:此控制器默认加载/WEB-INF下的xxx-servlet.xml文件
:其中xxx等于【DispatcherServlet的配置名】
-->
<servlet>
<servlet-name>mvc61</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:mvc62.xml</param-value>
</init-param>
<!-- 随项目启动而启动 -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc61</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <!-- 专治Post请求参数乱码 -->
<filter>
<filter-name>encoding61</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<!-- 将请求的编码方式设置为utf-8 -->
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding61</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

2.配置控制器

Class : JumpController

package com.c61.controller;

import java.util.Date;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView; import com.c61.entity.User;
import com.c61.entity.ValueObject; /**
*
* @author admin
* 收参测试 controller
*/
@Controller
@RequestMapping(value="/mvc2")//等价于namespace
public class JumpController { @RequestMapping("/jump1")
public String testJump1(){
System.out.println("jump1");
return "forward:/abc.jsp";//转发到 /abc.jsp
}
@RequestMapping("/jump2")
public String testJump2(){
System.out.println("jump2");
return "redirect:/view/abc.jsp";//重定向到 /abc.jsp
} /**
* 如下两个方法中在进行 C --> C 跳转
* 可以写相对路径或绝对路径
* 但是,进行跨namespace的跳转时,必须要用绝对路径
* @return
*/
@RequestMapping("/jump3")
public String testJump3(){
System.out.println("jump3");
//return "forward:jump1";//转发跳转到jump1中,【jump1】相对路径,相对于当前的namespace
//即,【jump1】等价于【/mvc2/jump1】
return "forward:/mvc2/jump1";//转发跳转到/mvc2/jump1中,绝对路径
} @RequestMapping("/jump4")
public String testJump4(){
System.out.println("jump4");
//return "redirect:jump2";//重定向跳转到jump1中,【jump2】相对路径,相对于当前的namespace
//即,【jump2】等价于【/mvc2/jump2】
//return "redirect:/mvc2/jump2";//重定向跳转到/mvc2/jump2中,绝对路径
return "redirect:/mvc3/jump9";
} //了解 ModelAndView
@RequestMapping("/jump5")
public ModelAndView testJump5(){
System.out.println("jump5");
ModelAndView mav=new ModelAndView();
mav.addObject("name", "lime");
mav.setViewName("forward:/mvc3/jump9");
return mav;
}
}

Class : JumpController2

package com.c61.controller;

import java.util.Date;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import com.c61.entity.User;
import com.c61.entity.ValueObject; /**
*
* @author admin
* 收参测试 controller
*/
@Controller
@RequestMapping(value="/mvc3")//等价于namespace
public class JumpController2 { @RequestMapping("/jump9")
public String testJump1(){
System.out.println("jump9 in mvc3");
return "forward:/abc.jsp";//转发到 /abc.jsp
} }

3 配置视图

View : jump.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<form action="${pageContext.request.contextPath}/mvc2/jump1">
<input type="submit" value="提交"/>
</form>
</body>
</html>

View : abc.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
This is my abc JSP page. <br>
name:${requestScope.name}
</body>
</html>

View : /view/abc.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
This is my abc JSP page. <br>
</body>
</html>

啦啦啦

SpringMVC -- 梗概--源码--壹--跳转的更多相关文章

  1. SpringMVC -- 梗概--源码--壹--springMVC json处理

    附:实体类 Class : User package com.c61.entity; import java.text.SimpleDateFormat; import java.util.Date; ...

  2. SpringMVC -- 梗概--源码--壹--数据传递

    附:实体类 Class : User package com.c61.entity; import java.text.SimpleDateFormat; import java.util.Date; ...

  3. SpringMVC -- 梗概--源码--壹--收参

    附:实体类 Class : User package com.c61.entity; import java.text.SimpleDateFormat; import java.util.Date; ...

  4. SpringMVC -- 梗概--源码--贰--下载

    1.配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=&qu ...

  5. SpringMVC -- 梗概--源码--贰--上传

    1.配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=&qu ...

  6. SpringMVC -- 梗概--源码--贰--拦截器:Interceptor

    附:实体类 1.配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app versi ...

  7. SpringMVC -- 梗概--源码--贰--异常管理

    附:实体类 Class : User package com.c61.entity; import java.text.SimpleDateFormat; import java.util.Date; ...

  8. SpringMVC -- 梗概--源码--贰--RestFul收参(了解) @PathVariable

    1>定制方式: //如下两个路径都可以访问到如下方法,请求路径不同,则name61和pwd61匹配到的值不同 //http://localhost:8989/appname/ful/lime/1 ...

  9. SpringMVC -- 梗概--源码--贰--mvc:annotation-driven

    1>在springMVC的处理流程中,有两个重要组件:HandlerMapping和HandlerAdapter 分别负责解析Handler和执行Handler 2>如果配置了<mv ...

随机推荐

  1. librtmp编译for android and ios 不要openssl

    git clone git://git.ffmpeg.org/rtmpdump 不想要openssl 在rtmp.h里面 #undef CRYPTO 编译动态库与静态库只需要修改下面的 #includ ...

  2. js关于弹也遮罩层

    1:什么是遮罩层 遮罩层:我是弹也一个(遮罩层)还有一个(内容层),下面上图片看一效果 我们看到一个灰蒙蒙的遮盖(其实也是一个层)还有一个层(也就是我们展示的内容). 2:  弹出层效果居中分析 在这 ...

  3. R语言-向量化操作(apply、tapply、lapply、sapply、mapply、table等)

    一.apply函数(对一个数组按行或者按列进行计算): 使用格式为:apply(X, MARGIN, FUN, ...) 其中X为一个数组:MARGIN为一个向量(表示要将函数FUN应用到X的行还是列 ...

  4. Reading and writing RData files

    前面添加个lapply()或者dplyr::llply()就能读取,储存多个文件了.http://bluemountaincapital.github.io/FSharpRProvider/readi ...

  5. Win7系统中MySQL服务无法启动的解决方法

    Win7系统中提示:本地无法启动MySQL服务,报的错误:1067,进程意外终止的解决方法.在本地计算机无法启动MYSQL服务错误1067进程意外终止.这种情况一般是my.ini文件配置出错了1.首先 ...

  6. USB集线器基础知识

    1.USB集线器又称为USB Hub,用于拓展计算机USB接口.计算机主板上对外往往提供多个USB接口,这些接口往往都是通过主板上的USB集线器芯片来拓展出来的.我们平常用的可以连接多个USB接口的设 ...

  7. SpringCloud微服务部署

    https://blog.csdn.net/weixin_36397925/article/details/79496657 https://blog.csdn.net/forezp/article/ ...

  8. 【CentOS】CentOS7.0 mysql与卸载

    mysql安装: 在使用命令 yum list mysql-server 安装mysql的时候,发现没有mysql的包.这时候,我们需要下载一个 下载包 wget http://repo.mysql. ...

  9. Winform控件学习笔记【第五天】——ListView

    [第五天] 常用的基本属性: FullRowSelect:设置是否行选择模式.(默认为false) 提示:只有在Details视图该属性才有意义. GridLines:设置行和列之间是否显示网格线.( ...

  10. YII2 搭建redis拓展

    安装redis扩展: 1.通过composer进行安装,到项目根目录cmd运行(推荐) php composer.phar require --prefer-dist yiisoft/yii2-red ...