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; |
11 |
Velocitycontext context = new Velocitycontext (); |