Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Struts velocity template
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ash
velocity template
1 Answer(s)      6 years ago
Posted in : Struts



Advertisement
View Answers

January 6, 2009 at 4:07 AM


Hi friend,

Velocity is an open source templating tool developed by an international volunteer community and hosted by the Apache Software Foundation's Jakarta Project.


Here is simple code:


import java.io.*;
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 {
VelocityEngine vengine = new VelocityEngine();
vengine.init();
// next, get the Template
Template temp = vengine.getTemplate("helloworld.vm");
//create a context and add data
VelocityContext context = new VelocityContext();
context.put("name", "World");
// now render the template into a StringWriter
StringWriter writer = new StringWriter();
temp.merge(context, writer);
System.out.println(writer.toString() );
}
}

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

Thanks.

Amardeep



Related Tutorials/Questions & Answers:
velocity template - Struts
velocity template  what is velocity template and how does it work? whats the flow of execution of velocity template? i want an example using velocity template?  Hi friend, Velocity is an open source templating tool
XML handling in a template using Velocity
XML handling in a template using Velocity   ... in a velocity template and also shows that use of  macro to wrap HTML tag in velocity  template. The method used in this example 
Advertisements
how to render my htmlstring from java class in velocity template?
how to render my htmlstring from java class in velocity template?  Hi, I have a java class generates html string dynamically based on the logic. I'm...! Ref: I read your article "Use Velocity to generate HTML document". -Chintu
Velocity
; Apache Velocity is template engine developed by apache foundation... applications. In this tutorial you will learn Velocity template with the help... you how to call class method in velocity template.   
Define and use Macro in Velocity
Define and use Macro in Velocity   ... in velocity  template and also shows how to use Iterator in velocity  template...:- Initialize velocity run time engine through method  init(). 2:- Create object
Velocity Macro with Parameters
Velocity Macro with Parameters   ... with parameters in velocity  template. Example given below show you, how to display date and time velocity. The method used in this example 
Velocity Iterator Tool Example
Velocity Iterator Tool Example     ...; template. The method used in this example are described below:-  1:- Initialize velocity run time engine through method  init(). 2:- Create object
How to use foreach loop in velocity
How to use foreach loop in velocity   ... in velocity  template. The method used in this example are described below:-  1:- Initialize velocity run time engine through method  init(). 2:- Create
XML and Velocity
XML and Velocity  How to create xml file using velocity template engine
What is Velocity?
What is Velocity?       Velocity is a Java-based template engine. It permits... Velocity Template Language (VTL): The Velocity
Show content of .vm file as output using Velocity
Show content of .vm file as output using Velocity  ... content of .vm file using velocity and also shows how to use Iterator in velocity  template. The method used in this example are described below:- 
Use macro to wrap HTML tags in velocity
Use macro to wrap HTML tags in velocity   ... in velocity  template. The method used in this example are described below:-  1:- Initialize velocity run time engine through method  init
Hibernate Template
Hibernate Template  Define Hibernate Template
XML template
XML template  Hi..... please tell me about What is XML template? Thanks
Use if in velocity
Use if in velocity       This example shows you how to use if statement in velocity. Description of methods used in the example given below.... 1:- Initialize velocity run time
Velocity with External Properties
for controlling template methods and properties. "runtime.log = velocity_example.log... Velocity with External Properties       This Example shows you how to use Velocity
The benefits of Hibernate Template.
The benefits of Hibernate Template.  What are the benefits of Hibernate Template
Use if and elseif statements in velocity
Use if and elseif statements in velocity   ... in velocity. The method used in this example are described below:-  1:- Initialize velocity run time engine through method  init(). 2
How to define variable in Velocity
How to define variable in Velocity   ... in velocity. Methods used in this example are described below:- 1:- Initialize velocity run time engine through method  init(). 2:- Create object
How to use List in velocity
How to use List in velocity       This Example shows you how to use List in velocity. ... velocity run time engine through method  init(). 2:- Create object
Use if else and end statements in velocity
Use if else and end statements in velocity  ... if in velocity. The method used in this example are described below:- 1:- Initialize velocity run time engine through method  init(). 2:- Create object
How to use Map in velocity
How to use Map in velocity       This Example shows you how to use map in velocity. The method... velocity run time engine through method  init(). 2:- Create object
Include template file in another template file
Include template file in another template file  ... template file. The method used in this example are described below:-  1:- Initialize velocity run time engine through method  init(). 2
Html Template - JSP-Servlet
Html Template   I use a template to design my website,but some problems arised using template.I pass flag update and insert as a hidden field on to the servlet,the response of the servlet is a jsp page.on this page template
Template - Java Beginners
Template  Develop a template for linked-list class along with its methods in Java
How to use dollar sign in velocity
How to use dollar sign in velocity   ... in velocity. The method used in this example are described below:- 1:- Initialize velocity run time engine through method  init(). 2:- Create object
Velocity Web Edit
Velocity Web Edit       Velocity Web Edit is a Velocity and HTML aware editor... Assist  Velocity Variables Names  Velocity Variable Methods
Integration of velocity with struts 2.0 - Struts
Integration of velocity with struts 2.0  Hi , I am going to implement Struts 2 with Velocity. Is there any plugin available? I am totally new to velocity. Please tell the steps to integrate Struts 2 and velocity
Replacing a template with actual values
Replacing a template with actual values  I have a template Hello $$personename$$, You are eligible for this $$planname$$ from today onwards. CONDITIONAL_TEXT_1 Regards,$$managerName$$ I wanna repalce this place
Formatting numbers in Velocity Templates?
Formatting numbers in Velocity Templates?  I need to display amount in following formats: 1099 -> 1,099.00 100 -> 100.00 100.251 -> 100.25 10999 -> 10,999.00 1110999 -> 11,10,999.00 Right now I am using
Formatting numbers in Velocity Templates?
Formatting numbers in Velocity Templates?  I need to display amount in following formats: 1099 -> 1,099.00 100 -> 100.00 100.251 -> 100.25 10999 -> 10,999.00 1110999 -> 11,10,999.00 Right now I am using
 

 

 

DMCA.com