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. python 语法最佳实践

    1. 列表推倒 我们知道, 列表类似于数组, 列表里存储的都是对象, 所以列表中可以存储"数字","字符串" 等对象. 列表用中括号扩起, 然后逗号分隔 列表内 ...

  2. 客户端Cookie读取操作

    function SetCookie(name,value) { //此 cookie 将被保存 30 天(可活动配置) var Days = 30; var exp = new Date(); ex ...

  3. 转载:案例用Excel对会员客户交易数据进行RFM分析

    案例:用Excel对会员客户交易数据进行RFM分析                                背景: 一个会员服务的企业,有近1年约1200个会员客户的收银数据.由于公司想针对不同 ...

  4. e867. 获取和设置外观

    To change the look and feel, you need to know the class name of the new look and feel. This example ...

  5. jQuery Validation让验证变得如此easy(二)

    上一个样例我们是统一引用jquery.validate.js这样全部必填字段的提示信息都将是This field is required. 如今要改成动态提示,比方姓名假设为空则提示姓名不能为空,密码 ...

  6. Remote SSH: Using JSCH with Expect4j

    Now-a-days, we can see that whole world is moving around Clouds and virtualization. More and more ap ...

  7. 查看已装TensorFlow的版本和路径

    pyhton Python 2.7.14... >>>import tensorflow as tf >>>tf.__version__ '1.3.0'>&g ...

  8. iOS : 判断运行设备类型是否是iPad

    以下代码由 CocoaChina 版主 “cclv” 分享,可用于判断应用运行的设备是否是 iPad #define isPad (UI_USER_INTERFACE_IDIOM() == UIUse ...

  9. 通过tarball形式安装HBASE Cluster(CDH5.0.2)——配置分布式集群中的YARN ResourceManager 的HA

    <?xml version="1.0"?> <!-- Licensed under the Apache License, Version 2.0 (the &q ...

  10. Linux服务器安装svn

    云安装 yum install subversion 配置 1.配置仓库 [root@localhost /]# cd /home [root@localhost home]# mkdir svn [ ...