velocity配置与springMVC

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" version="2.5">
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:spring/**/*.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
  </listener>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath*:/mvc/spring-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <!-- 
    <servlet>
    <servlet-name>velocity</servlet-name>
    <servlet-class>
      org.apache.velocity.tools.view.servlet.VelocityViewServlet
    </servlet-class>
    <load-on-startup>10</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>velocity</servlet-name>
    <url-pattern>*.html</url-pattern>
  </servlet-mapping>
   -->
  <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/app/*</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

spring-mvc.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"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd 
	 http://www.springframework.org/schema/aop 
  http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
  http://www.springframework.org/schema/mvc 
			http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
	<mvc:annotation-driven />
		
	<context:component-scan base-package="com.nahai.view.controller" />
	
	<context:annotation-config />
	<!-- <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
		<property name="basenames"> <list> <value>/WEB-INF/messages/messages</value> 
		<value>/WEB-INF/messages/expMessages</value> <value>/WEB-INF/messages/chartMessages</value> 
		</list> </property> <property name="cacheSeconds" value="-1" /> </bean> \ -->
	
	<!--  解析器-->
	<!-- <bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver"
		p:prefix="/view/" p:suffix=".html" /> --> 
	
	    <!-- velocity解析器 -->
     <bean id="viewResolver"
                        class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"> 
                        <property name="contentType" 
                            value="text/html;charset=UTF-8" />
                         <property name="suffix" value=".html" /> 
    </bean> 
		
     <!-- velocity引擎 -->
    <bean id="velocityConfigurer" 
        class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> 
        <property name="resourceLoaderPath"> 
            <value>/view/</value> 
        </property> 
        <!--<property name="configLocation" value="/WEB-INF/velocity.properties" />  -->
        <property name="velocityProperties">   
         <props>   
             <prop  key="input.encoding">UTF-8</prop>   
             <prop  key="output.encoding">UTF-8</prop>     
          </props>   
      </property>   
    </bean> 
</beans>

maven

<dependency>
       <groupId>velocity</groupId>
        <artifactId>velocity</artifactId>
        <version>1.7</version>
        <systemPath>D:/workspace/showView/src/main/webapp/WEB-INF/lib/velocity-1.7.jar</systemPath>
        <scope>system</scope>
	</dependency>
	<dependency>
       <groupId>velocity</groupId>
        <artifactId>velocity-tools-view-2.0.jar</artifactId>
        <version>2.0</version>
        <systemPath>D:/workspace/showView/src/main/webapp/WEB-INF/lib/velocity-tools-2.0.jar</systemPath>
        <scope>system</scope>
	</dependency>
	<dependency>
       <groupId>commons</groupId>
        <artifactId>collections.jar</artifactId>
        <version>1.0</version>
        <systemPath>D:/workspace/showView/src/main/webapp/WEB-INF/lib/commons-collections.jar</systemPath>
        <scope>system</scope>
	</dependency>
     <dependency>
       <groupId>commons</groupId>
        <artifactId>lang.jar</artifactId>
        <version>1.0</version>
        <systemPath>D:/workspace/showView/src/main/webapp/WEB-INF/lib/commons-lang.jar</systemPath>
        <scope>system</scope>
	</dependency>
	  <dependency>
       <groupId>commons</groupId>
        <artifactId>commons-digester-1.8.jar</artifactId>
        <version>1.8</version>
        <systemPath>D:/workspace/showView/src/main/webapp/WEB-INF/lib/commons-digester-1.8.jar</systemPath>
        <scope>system</scope>
	</dependency>
		  <dependency>
       <groupId>commons</groupId>
        <artifactId>commons-beanutils-1.8.3.jar</artifactId>
        <version>1.8</version>
        <systemPath>D:/workspace/showView/src/main/webapp/WEB-INF/lib/commons-beanutils-1.8.3.jar</systemPath>
        <scope>system</scope>
	</dependency>

相关推荐