Velocity, like freemaker, is a template generation engine. However, it has recently encountered Chinese problems during usage and finally solved the problem after querying the information. My environment is Tomcat 5.0.28. servlet is used in the program and filter is used. The file header of the VM template is also added.
% @ Page... %, but garbled. The solution is as follows:
First of all, remember to download velocity 1.4, but also download the velocity tools 1.2 compressed package, decompress, The veloctiy-tools.jar and velocity. jar is put together in the Web-INF \ Lib file, and in the web. in XML, configure velocity as follows:
<Servlet>
<Servlet-Name> velocity </servlet-Name>
<Servlet-class>
Org. Apache. Velocity. Tools. View. servlet. velocityviewservlet
</Servlet-class>
<Init-param>
<Param-Name> org. Apache. Velocity. toolbox </param-Name>
<Param-value>/WEB-INF/toolbox. xml </param-value>
</Init-param>
<Init-param>
<Param-Name> org. Apache. Velocity. properties </param-Name>
<Param-value>/WEB-INF/velocity. properties </param-value>
</Init-param>
<Load-on-startup> 10 </load-on-startup>
</Servlet>
Put the tools. xml and velocity. properties files under Web-INF.
For more information about tools. XML, see http://www.blogjava.net/hiswing/archive/2006/08/21/64746.html,
Velocity. proerties, you can refer to the files in velocity, but you need to modify
Input. Encoding = gb2312
Output. Encoding = gb2312
In this way, you can correctly process Chinese characters. Otherwise, even with Servlet filters, Chinese characters cannot be correctly displayed.