SpringMVC -- 梗概--源码--壹--跳转
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 -- 梗概--源码--壹--跳转的更多相关文章
- SpringMVC -- 梗概--源码--壹--springMVC json处理
附:实体类 Class : User package com.c61.entity; import java.text.SimpleDateFormat; import java.util.Date; ...
- SpringMVC -- 梗概--源码--壹--数据传递
附:实体类 Class : User package com.c61.entity; import java.text.SimpleDateFormat; import java.util.Date; ...
- SpringMVC -- 梗概--源码--壹--收参
附:实体类 Class : User package com.c61.entity; import java.text.SimpleDateFormat; import java.util.Date; ...
- SpringMVC -- 梗概--源码--贰--下载
1.配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=&qu ...
- SpringMVC -- 梗概--源码--贰--上传
1.配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=&qu ...
- SpringMVC -- 梗概--源码--贰--拦截器:Interceptor
附:实体类 1.配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app versi ...
- SpringMVC -- 梗概--源码--贰--异常管理
附:实体类 Class : User package com.c61.entity; import java.text.SimpleDateFormat; import java.util.Date; ...
- SpringMVC -- 梗概--源码--贰--RestFul收参(了解) @PathVariable
1>定制方式: //如下两个路径都可以访问到如下方法,请求路径不同,则name61和pwd61匹配到的值不同 //http://localhost:8989/appname/ful/lime/1 ...
- SpringMVC -- 梗概--源码--贰--mvc:annotation-driven
1>在springMVC的处理流程中,有两个重要组件:HandlerMapping和HandlerAdapter 分别负责解析Handler和执行Handler 2>如果配置了<mv ...
随机推荐
- 《VS2010/MFC编程入门教程》——读书笔记
推荐两个比较好的学习网站:http://v.dxsbb.com/jisuanji/555/ http://www.jizhuomi.com/software/257.html MFC全称Microso ...
- R语言如何将字符串转变为命令执行
这里用到 eval() 和 parse() 函数.首先使用 parse() 函数将字符串转化为表达式(expression),而后使用 eval() 函数对表达式求解.x <- 1:10a &l ...
- 6、Qt Meta Object system 学习
原文地址:http://blog.csdn.net/ilvu999/article/details/8049908 使用 meta object system 继承自 QOject 类定义中添加 Q_ ...
- SSh on Ubuntu
ssh程序分为有客户端程序openssh-client和服务端程序openssh-server.如果需要ssh登陆到别的电脑,需要安装openssh-client,该程序Ubuntu是默认安装的.而如 ...
- 关于VS2008和VS2013中字体的选择
我这学期上ASP.NET的课,用C#语言,配合VS2008.自己课余在研究手机游戏的开发,用的是C++语言,配合VS2013.这两种开发环境我自己试过好多字体,后来感觉适合我自己的应该是以下这两种: ...
- JUnit规则
在本节中,我们学习和了解JUnit中叫做规则的新功能,它允许非常灵活在测试类重新定义每个测试方法的行为.为了这个目的,@Rule注解被使用来标出测试类的公共字段.这些字段类型为MethodRule,这 ...
- 使用Maven构建项目
要构建一个基于Maven的项目,打开控制台,进入到 pom.xml 文件所放的项目文件夹,并发出以下命令: mvn package 这将执行Maven的“package”阶段. Maven构建生命周期 ...
- unity提高----------射线使用【unity3d 怎样获得当前鼠标点击的对象】
unity3d 怎样获得当前鼠标点击的对象 最佳答案 var ray = Camera.main.ScreenPointToRay (Input.mousePosition);var hit : ...
- (转) 解密H264、AAC硬件解码的关键扩展数据处理
出自:http://blog.itpub.net/30168498/viewspace-1576794/ 通过上一篇文章,我们用ffmpeg分离出一个多媒体容器中的音视频数据,但是很可能这 ...
- (转)Live555中RTSPClient分析
有RTSPServer,当然就要有RTSPClient. 如果按照Server端的架构,想一下Client端各部分的组成可能是这样:因为要连接RTSP server,所以RTSPClient要有TCP ...