velocity初学指南2
2007-08-22 09:21
489 查看
velocity初学指南2
Hello from $name in the $project 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 );
}
}
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=535805
Hello from $name in the $project 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 );
}
}
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=535805
相关文章推荐
- Velocity初学指南1
- MYSQL初学指南
- 给C++程序员的Python初学指南 / Guide to Python for C++ Programmers
- 初学 Anroid 报错指南
- mysql初学指南
- Spring Framework标记库初学指南
- Velocity入门指南——第一章 快速入门
- velocity1.4模板使用指南中文版
- Hadoop初学指南(1)--Hadoop1伪分布模式的安装
- Hadoop初学指南(4)--使用java操作HDFS
- Velocity用户指南(三)
- eclipse开发velocity实例(初学)
- Velocity的中文指南(5)-整理
- DDD初学指南
- c#初学-使用 Override 和 New 关键字进行版本控制(C# 编程指南)
- 《Velocity 模板使用指南》中文版
- Velocity用户指南(中文版)(1)
- 《Velocity 模板使用指南》中文版
- Web开发从前端、后端、编程语言、到框架的初学指南
- velocity用户指南 超全面的中文教材