Velocity的工作过程
2009-08-13 20:36
92 查看
Velocity的工作过程主要分为五个阶段
Velocity初始化
创建上下文(Context)
添加数据到上下文中
选择模版
将上下文中的数据与模版融合(merge)
具体实现过程参考一下代码(详细参考APACHE网站)
import java.io.StringWriter;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.Template;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.MethodInvocationException;
Velocity.init();
VelocityContext context = new VelocityContext();
context.put( "name", new String("Velocity") );
Template template = null;
try
{
template = Velocity.getTemplate("mytemplate.vm");
}
catch( ResourceNotFoundException rnfe )
{
// couldn't find the template
}
catch( ParseErrorException pee )
{
// syntax error: problem parsing the template
}
catch( MethodInvocationException mie )
{
// something invoked in the template
// threw an exception
}
catch( Exception e )
{}
StringWriter sw = new StringWriter();
template.merge( context, sw );
Velocity初始化
创建上下文(Context)
添加数据到上下文中
选择模版
将上下文中的数据与模版融合(merge)
具体实现过程参考一下代码(详细参考APACHE网站)
import java.io.StringWriter;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.Template;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.MethodInvocationException;
Velocity.init();
VelocityContext context = new VelocityContext();
context.put( "name", new String("Velocity") );
Template template = null;
try
{
template = Velocity.getTemplate("mytemplate.vm");
}
catch( ResourceNotFoundException rnfe )
{
// couldn't find the template
}
catch( ParseErrorException pee )
{
// syntax error: problem parsing the template
}
catch( MethodInvocationException mie )
{
// something invoked in the template
// threw an exception
}
catch( Exception e )
{}
StringWriter sw = new StringWriter();
template.merge( context, sw );
相关文章推荐
- 嵌入式C学习笔记(二) 编译器-GCC的工作过程
- 工作中的那些坑(1)——一次过滤存量数据的优化过程
- ARM的异常处理过程分析(异常向量/工作模式)
- Activity启动的工作过程知识点
- 编译器的工作过程
- Berkeley Socket工作过程(面向连接&无连接)
- 编译器的工作过程
- windowsphone7推送服务工作过程
- 工作过程的编译器
- ntp工作过程
- voip通话中SIP/SDP/RTP/RTCP的工作过程
- 编译器的工作过程-节选自阮一峰的博文中并加以整理
- PPP协议工作过程
- 人工智能AI常见的经典K-means聚类算法原理和工作过程
- ContentProvider的工作过程
- 编译器的工作过程
- Velocity初始化过程解析
- MapReduce程序的工作过程
- 通过制定编码规范的过程来说明《学会放弃、妥协也是个大进步,也是相当的提高工作效率》
- 微程序控制器之微程序控制的工作过程