Notes for using velocity in Chinese

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.