Loading
Velocity Engine

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  Java Template Engine ? Velocity Engine ?


  • Velocity Engine
    Sample Img 10

Ans)

A template engine is software that is designed to process the templates and

content information to produce output web documents. It runs in the context of a template system.

Some of the Popular Java Based Templating Egines are "FreeMarker","Velocity"

Quick example of Velocity Template :

Step 1: Create a .vm file

sayHello.vm:
  Hello $name !  How are you ?

Sample : input this to ve.getTemplate()
 
import java.io.StringWriter;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
public class HelloWorld
{
    public static void main( String[] args )
        throws Exception
    {
        /* initialize an engine  */
        VelocityEngine ve = new VelocityEngine();
        ve.init();
 
        /*  get the Template  */
        Template t = ve.getTemplate( "sayHello.vm" );
      
  /*  create a contex */
        VelocityContext context = new VelocityContext();
        context.put("name", "John");
 
        StringWriter writer = new StringWriter();
      
  t.merge( context, writer );
 
        System.out.println( writer.toString() );   
    }
}


Output : Please see below Name is replaced with "John"

Hello John !  How are you ?



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

Velocity Engine


Velocity Engine

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free