Hello from $ name in the $ project.
*
Import org. Apache. Velocity. Exception. methodinvocationexception;
Import org. Apache. Velocity. Exception. parseerrorexception;
Import org. Apache. Velocity. App. velocity;
Import org. Apache. Velocity. velocitycontext;
Import java. Io. stringwriter;
/**
* Created by intellij idea.
* User: Leo
* Date: 2005-11-22
* Time: 20:22:41
* To change this template use file | Settings | file templates.
*/
Public class mytest {
Public static void main (string [] ARGs ){
Try
{
Velocity. INIT ();
}
Catch (exception E)
{
System. Out. println ("problem initializing velocity:" + E );
Return;
}
Velocitycontext context = new velocitycontext ();
Context. Put ("name", "velocity ");
Context. Put ("project", "Leo ");
Stringwriter W = new stringwriter ();
Try
{
Velocity. mergetemplate ("example2.vm", "gb2312", context, W );
}
Catch (exception E)
{
System. Out. println ("problem merging template:" + E );
}
System. Out. println ("template:" + W );
String S = "we are using $ project $ name to render this .";
W = new stringwriter ();
Try
{
Velocity. Evaluate (context, W, "mystring", S );
}
Catch (parseerrorexception pee)
{
System. Out. println ("parseerrorexception:" + pee );
}
Catch (methodinvocationexception MEE)
{
System. Out. println ("methodinvocationexception:" + MEE );
}
Catch (exception E)
{
System. Out. println ("exception:" + E );
}
System. Out. println ("string:" + W );
}
}