How the Velocity official guide-velocity works

Source: Internet
Author: User

Basic Mode

When you use velocity in an application or a servlet, or anywhere else, it is usually handled as follows: Initialize velocity. Velocity can use two modes as a singleton mode for "separate runtime instances" (described in the following section), and you only need to initialize them once. Create a Context object (this is what is described later). Add your data object to the context. Select a template. The ' merge ' template and your data output.

In the code, using the singleton pattern through the Org.apache.velocity.app.Velocity class, the code is as follows:

01 Import Java.io.StringWriter;
02 Import Org.apache.velocity.VelocityContext;
03 Import Org.apache.velocity.Template;
04 Import org.apache.velocity.app.Velocity;
05 Import org.apache.velocity.exception.ResourceNotFoundException;
06 Import org.apache.velocity.exception.ParseErrorException;
07 Import org.apache.velocity.exception.MethodInvocationException;
08
09 Velocity.init ();
10
11 Velocitycontext context = new Velocitycontext ();

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.