How Velocity works

Source: Internet
Author: User

When Using Velocity in an application or servlet, you need to do the following:

  1. Initialize Velocity. Velocity provides two usage modes: single instance mode and single instance mode. The initialization process is only performed once.
  2. Create context object
  3. Add data objects to the context
  4. Select Template
  5. 'Merge' template and execute data output

In the code, by using the org. apache. velocity. app. Velocity class single instance mode

VelocityContext context = context. put ("name", String ("Velocity" Template template = Velocity. getTemplate ("mytemplate. vm "StringWriter sw = template. merge (context, sw );

This is a basic form, which is very simple, right? This is what you do when using Velocity to present a template. You may not need to write code like this-we provide some tools to make it easier to use. In any case, no matter how Velocity is used, the above execution sequence will actually happen in the background.

Related Article

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: 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.