014 view-controller标签

1.说明

  可以直接相应转发的页面, 而无需再经过 Handler 的方法.

  这个时候可以使用mvc:view-controller标签。

  但是以前的映射会出现问题,这个时候需要再配置一个标签<mvc:annotation-driven></mvc:annotation-driven>

2.程序

  注意点:需要在头上添加mvc

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:context="http://www.springframework.org/schema/context"
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5     xmlns:mvc="http://www.springframework.org/schema/mvc"
 6     xsi:schemaLocation="http://www.springframework.org/schema/beans     
 7                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 8                        http://www.springframework.org/schema/context 
 9                        http://www.springframework.org/schema/context/spring-context-3.0.xsd
10                        http://www.springframework.org/schema/mvc 
11                        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
12     <!-- 配置自定义扫描的包 -->               
13     <context:component-scan base-package="com.spring.it" ></context:component-scan>
14     
15     <!-- 配置视图解析器 -->
16     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
17         <property name="prefix" value="/WEB-INF/views/" />
18           <property name="suffix" value=".jsp" />
19     </bean>
20     
21     <!-- 配置国际化资源文件 -->
22     <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
23         <property name="basename" value="i18n"></property>
24     </bean>
25     
26     <!-- 配置直接转发的页面 -->
27     <!-- 可以直接相应转发的页面, 而无需再经过 Handler 的方法.  -->
28     <mvc:view-controller path="/success" view-name="success"/>
29     
30     <!-- 在实际开发中通常都需配置 mvc:annotation-driven 标签 -->
31     <mvc:annotation-driven></mvc:annotation-driven>
32 </beans>

3.可以直接使用

  http://localhost:8080/HelloworldMVC/success

  

原文地址:https://www.cnblogs.com/juncaoit/p/8476453.html