1.在pom.xml中添加依赖
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<version>2.0</version>
</dependency>
2.从velocity-tools-2.0.jar的org.apache.velocity.tools.view包中复制出velocity.properties和tools.xml文件
到WEB-INF目录下,修改velocity.properties:
[plain]
- input.encoding=UTF-8
- output.encoding=UTF-8
3.配置web.xml文件中的servlet
[html]
- <servlet>
- <servlet-name>velocity</servlet-name>
- <servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class>
- <init-param>
- <param-name>org.apache.velocity.properties</param-name>
- <param-value>/WEB-INF/velocity.properties</param-value>
- </init-param>
- <init-param>
- <param-name>org.apache.velocity.toolbox</param-name>
- <param-value>/WEB-INF/tools.xml</param-value>
- </init-param>
- </servlet>
- <servlet-mapping>
- <servlet-name>velocity</servlet-name>
- <url-pattern>*.vm</url-pattern>
- </servlet-mapping>