我的项目名称是hello,

在src/main/java目录下面建了一个chapter2目录

有三个配置文件: web.xml, chapter2-servlet.xml, applicationContext.xml

三个配置如下:

web.xml

<web-app>

  <display-name>Archetype Created Web Application</display-name>

<!--配置文件路径-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <servlet>
<servlet-name>chapter2</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>chapter2</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> </web-app>

  

applicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"> <!-- ViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean> </beans>

  chapter2-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 默认的注解映射的支持 -->
<mvc:annotation-driven />
<!-- 静态资源 -->
<mvc:resources mapping="/pages/**" location="/pages/"/> <!-- 自动扫描的包名 -->
<context:component-scan base-package="chapter2.*" /> </beans>

  

接下来看代码实现:

WeboneController.java

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; @Controller
public class WeboneController { @RequestMapping(value="/webone/index", method=RequestMethod.GET)
public String index()
{
return "webone_index"; } //重定向跳转
@RequestMapping(value="/webone/redirect", method=RequestMethod.GET)
public String redirect()
{
return "redirect:finalPage"; } @RequestMapping(value="/webone/finalPage", method=RequestMethod.GET)
public String finalPage()
{
return "webone_final"; }
}

  

jsp页面

webone_index.jsp

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>webone index</title>
</head>
<body> <form:form method="GET" action="/hello/webone/redirect">
<table>
<tr>
<td><input type="submit" value="重定向跳转"/> </td>
</tr>
</table>
</form:form> </body>
</html>

  webone_fina.jsp

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>web-one finalPage spring mvc重定向页面<</title>
</head>
<body> <h2>spring mvc重定向页面</h2> </body>
</html>

  

实际我的 访问地址如下: http://localhost:8080/hello/webone/index

点击里面的跳转按钮,会自动跳转到:http://localhost:8080/hello/webone/finalPage

最新文章

  1. css3-无缝滚动
  2. [zt]OpenCV如何获取视频当前的一帧图像
  3. go can&#39;t find import: &quot;github.com/** 错误
  4. how to Enable Client Integration
  5. WebGL on iOS8 最终等到了这一天
  6. 嵌入式C开发人员的最好的0x10道笔试题
  7. visual studio 2010 无法连接到ASP.NET Development Server
  8. sicily 1063. Who&#39;s the Boss 排序+递推
  9. Andrew Ng机器学习课程笔记(五)之应用机器学习的建议
  10. OSGi-开发环境的建立和HelloWorld(04)
  11. 简洁灵活的前端框架------BootStrap
  12. 3D位置语音,引领吃鸡游戏体验升级
  13. 有效防止softmax计算时上溢出(overflow)和下溢出(underflow)的方法
  14. PHP实现多维数组按指定值排序
  15. 环境部署(二):Linux下安装jenkins
  16. python 的基础 学习第十天函数的初始
  17. JVM之对象分配:栈上分配 &amp; TLAB分配
  18. Spark VS Presto VS Impala
  19. e577. Enabling Antialiasing
  20. mac环境搭建selenium

热门文章

  1. php strtok()函数用法,及使用时遇到的问题
  2. flink hadoop yarn
  3. 邮件发送异常, [Errno 110] Connection timed out
  4. 阻塞IO、非阻塞IO、同步IO、异步IO等
  5. js实现模糊查询
  6. 重置Linux普通账号和root账号密码
  7. CRM项目问答总结
  8. Codeforces Round #302 (Div. 2)
  9. JavaScript:学习笔记(7)——VAR、LET、CONST三种变量声明的区别
  10. NIO复习02