Share on Google+Share on Google+

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

Ads

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
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
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
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 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
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
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
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
Tutorials   
Java Spring Hibernate Struts Training Dynamic tabs in struts 1.2 Unable to upload a file to mysql database using struts1 Pagination in struts 2 struts2 filterdispatcher is deprecated please use the new filters viewing How to add struts2 dependency in Maven? Struts Exception Handling can you check below code if any erors multimedia how to display the value of termcell name in label class not found exception Where to learn Struts 2? dropdown cacheing Upload and Download Large files in jsp What is Struts 2 framework struts and hibernate based health care project source code struts and hibernate based health care project source code Struts 2 Integration with Struts 1 About captcha of strut2 About captcha of strut2 Which is the good website for struts 2 tutorials? advance java source code source code In Struts 2 how to pass the Struts struts internationalization for Korean language struts2 Struts2 and Hibernate Fetch Data Base Value Struts2 and Hibernate Fetch Data Base Value Struts2 and Hibernate i want to create an application with only a button which on click displays table from database using struts2 and hibernate on eclipse Struts2 and Hibernate Struts2 and Hibernate Struts2 validation Procedure Struts2 validation Procedure Struts2 validation Procedure Struts2 validation Procedure Struts 2 action-validation.xml not loading Struts-2 and Ajax integration STRUTS QUESTION conerting web project into .exe file About Select tag ScartApplication aplicacion ecommerce struts 1.3 struts 1.3 sms prob Need to know struts1 all jar file names struts with hibernate

Ads

 
Advertisement null

Ads