1. Add in Pom.xml Dependent
1 <Dependency>2 <groupId>Org.apache.velocity</groupId>3 <Artifactid>Velocity</Artifactid>4 <version>1.7</version>5 </Dependency>6 <Dependency>7 <groupId>Org.apache.velocity</groupId>8 <Artifactid>Velocity-tools</Artifactid>9 <version>2.0</version>Ten </Dependency>
2. Copy the velocity.properties and Tools.xml files from the Velocity-tools-2.0.jar Org.apache.velocity.tools.view package
To the Web-inf directory, modify the velocity.properties:
Input.encoding=utf-8output.encoding=utf-8
3. Configure the servlet in the Web. xml File
<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>
Use of velocity-configuration (Maven)