在springmvc中使用mvc:view-controller标签直接将访问url和视图进行映射,而无需要通过控制器。

参考springmvc.xml内容:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
  8. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">
  9.  
  10. <!-- 配置自动扫描包 -->
  11. <context:component-scan base-package="com.tiekui.springmvc.handlers"></context:component-scan>
  12.  
  13. <!-- 配置视图解析器:如何把handler方法返回给视图 -->
  14. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  15. <property name="prefix" value="/WEB-INF/views/"></property>
  16. <property name="suffix" value=".jsp"></property>
  17. </bean>
  18.  
  19. <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
  20. <property name="basename" value="i18n"></property>
  21. </bean>
  22.  
  23. <mvc:view-controller path="/testMvcViewController" view-name="success" />
  24. </beans>

参考视图代码index.jsp

  1. <a href="testMvcViewController">MVC View Controller Test Video 26</a>

参考视图返回代码success.jsp

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5. <html lang="en">
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  8. <title>Insert title here</title>
  9. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
  10. </head>
  11. <body>
  12. <h1>Hello SpringMVC View</h1>
  13.  
  14. <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
  15. <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
  16. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
  17. </body>
  18. </html>

SpringMVC(二六) SpringMVC配置文件中使用mvc:view-controller标签的更多相关文章

  1. log4net保存到数据库系列二:独立配置文件中配置log4net

    园子里面有很多关于log4net保存到数据库的帖子,但是要动手操作还是比较不易,从头开始学习log4net数据库日志一.WebConfig中配置log4net 一.WebConfig中配置log4ne ...

  2. UIStoryboard类介绍(如何从Storyboard中加载View Controller)

    如何从Storyboard中加载View Controller? 1. 首先了解下UIStoryboard类: @class UIViewController; @interface UIStoryb ...

  3. spring boot配置文件中 spring.mvc.static-path-pattern 配置项

    spring boot项目中的静态资源文件存放在static文件下面,当通过浏览器访问这些静态文件时,发现必须要添加static作为前缀才能访问,折腾了一番后发现,这个前缀跟 spring.mvc.s ...

  4. (转)SpringMVC学习(六)——SpringMVC高级参数绑定与@RequestMapping注解

    http://blog.csdn.net/yerenyuan_pku/article/details/72511749 高级参数绑定 现在进入SpringMVC高级参数绑定的学习,本文所有案例代码的编 ...

  5. SqlMapConfig.xml配置文件中的mapper映射器标签

    Mapper配置的几种方式: 1. <mapper resource=" "/> 使用相对于类路径的资源 如:<mapper resource="com ...

  6. 浅谈SpringMVC(二)

    一.SpringMVC的拦截器 1.写类implements HandlerInterceptor public class MyMvcInterceptor implements HandlerIn ...

  7. SpringMVC <mvc:view-controller path=""/>标签

    <mvc:view-controller path=""/>标签的作用 对应WEB-INF目录下面的JSP页面,我们知道是不能直接使用URL访问到.需要通过转发的方式, ...

  8. (转)SpringMVC学习(三)——SpringMVC的配置文件

    http://blog.csdn.net/yerenyuan_pku/article/details/72231527 读者阅读过SpringMVC学习(一)——SpringMVC介绍与入门这篇文章后 ...

  9. 初探SpringMVC,走进SpringMVC的世界

    1.Springmvc入门 1.1.Springmvc是什么 SpringMVC是Spring中的一个组件,目前(2019)在互联网公司用的很多,是必需学习的一门框架技术!SpringMVC用于web ...

随机推荐

  1. php回调函数的概念及实例

    php提供了两个内置函数call_user_func()和call_user_func_array()提供对回调函数的支持.这两个函数的区别是call_user_func_array是以数组的形式接收 ...

  2. Eclipse搭建C++\C开发环境

    1.最近使用visualStudio IDE开发Unity 3D使用的编程语言是C#但是发现visualStudio12 版本在自己主机上运行速度比够快,怀疑是不是处理器或者是版本问题,所以该卸载了, ...

  3. 最小标示法模板 poj1509

    最小标示法:给定一个字符串,不断将其最后一个字符放到开头,最终会得到n个字符串,称这n个字符串循环同构,这些字符串中字典序最小的一个,就是最小表示法 #include<iostream> ...

  4. str类型

    str:字符串类型,用单引号或双引号. #索引 s1 = s[0] 切片 : 顾头不顾尾 : s[首:尾:步长] 字符串的操作: 1.首字母大写: s = 'alexWUsir' s1 = s.cap ...

  5. Python使用re模块实现正则表达式操作

    Python提供了re模块,用于实现正则表达式的操作.在实现时,可以使用re模块提供的方法(如search().match().findall()等)进行字符串处理,也可以先使用re模块的compil ...

  6. RabbitMQ中客户端的Channel类里各方法释义

    // The contents of this file are subject to the Mozilla Public License // Version 1.1 (the "Lic ...

  7. Cookie中设置了 HttpOnly,Secure 属性,有效的防止XSS攻击,X-Frame-Options 响应头避免点击劫持

    属性介绍: 1) secure属性当设置为true时,表示创建的 Cookie 会被以安全的形式向服务器传输(ssl),即 只能在 HTTPS 连接中被浏览器传递到服务器端进行会话验证, 如果是 HT ...

  8. 通过awk 和 sed 将多余的列剔除

    通过awk 和 sed 将多余的列剔除 名词注释: awk -F 指定分隔符 OFS 指定输出分隔符 sed sed "s/|/test/2" a.log 将第二个 | 线替换为 ...

  9. 【C#】wpf中的xmlns命名空间为什么是一个网址,代表了什么意思(转载)

    原文:https://blog.csdn.net/catshitone/article/details/71213371 新建一个wpf的项目,我们先来看下它默认的命名空间都是哪些? 可以看到xmln ...

  10. python---手动实现两个有序列表的合并

    可能又和标准的实现不一样, 但是自己的实现, 印象就会不一样的. # coding = utf-8 # 两个有序列表的合并,将two_list合并到one_list def merge_order_l ...