Spring 同时使用多个视图

参考:http://www.iteye.com/problems/55772



Pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.wodwl</groupId>
  <artifactId>jiajia</artifactId>
  <version>0.0.1</version>
  <packaging>war</packaging>
  <build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.3.1</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>2.5</version>
				<configuration>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
		</plugins>
	</build>
  <dependencies>
  	<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>3.0.4.RELEASE</version>
</dependency>
<dependency>
    <groupId>velocity</groupId>
    <artifactId>velocity</artifactId>
    <version>1.5</version>
</dependency>
  </dependencies>
</project>

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>hello</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  	<servlet> 
        <servlet-name>jstl</servlet-name> 
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    </servlet> 
    <servlet-mapping> 
        <servlet-name>jstl</servlet-name> 
        <url-pattern>*.do</url-pattern> 
    </servlet-mapping> 
    <servlet> 
        <servlet-name>html</servlet-name> 
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    </servlet> 
    <servlet-mapping> 
        <servlet-name>html</servlet-name> 
        <url-pattern>*.ht</url-pattern> 
    </servlet-mapping> 
     <servlet> 
        <servlet-name>vm</servlet-name> 
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    </servlet> 
    <servlet-mapping> 
        <servlet-name>vm</servlet-name> 
        <url-pattern>*.vm</url-pattern> 
    </servlet-mapping> 
</web-app>

jstl-servlet.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context-2.5.xsd"> 
      <context:annotation-config />   
       <!-- 把标记了@Controller注解的类转换为bean -->     
      <context:component-scan base-package="com.wodwl.controller" /> 
    <!-- 视图 --> 
    <bean id="viewResolver" 
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
        <!-- 使用标签库,暂时可不用 --> 
        <!-- <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> --> 
        <property name="prefix" value="/jsp/" /> 
        <property name="suffix" value=".jsp" /> 
    </bean> 
 
</beans> 

vm-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">
	<context:annotation-config />
	<!-- 把标记了@Controller注解的类转换为bean -->
	<context:component-scan base-package="com.wodwl.controller" />

	<bean id="velocityConfigurer"
		class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
		<property name="configLocation">
			<value>classpath:velocity-web.properties</value>
		</property>
	</bean>

	<bean id="velocityResolver"
		class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
		<property name="order" value="1" />
		<property name="contentType">
			<value>text/html;charset=utf-8</value>
		</property>
		<property name="suffix">
			<value>.vm</value>
		</property>
	</bean>

</beans> 


src/main/resources/velocity-web.properties

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">
	<context:annotation-config />
	<!-- 把标记了@Controller注解的类转换为bean -->
	<context:component-scan base-package="com.wodwl.controller" />

	<bean id="velocityConfigurer"
		class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
		<property name="configLocation">
			<value>classpath:velocity-web.properties</value>
		</property>
	</bean>

	<bean id="velocityResolver"
		class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
		<property name="order" value="1" />
		<property name="contentType">
			<value>text/html;charset=utf-8</value>
		</property>
		<property name="suffix">
			<value>.vm</value>
		</property>
	</bean>

</beans> 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值