使用VELOCITY生成文件
来源:互联网 发布:软件设计方案 评价 编辑:程序博客网 时间:2024/05/21 11:16
VelocityEngine velocity = new VelocityEngine();
Properties properties = new Properties();
//设置属性
。。。。
velocity.init(properties);
// ファイルWriter
Writer writer = null;
try {
String charSet = "UTF-8";
Template template = velocity .getTemplate(”PACKAGE+文件名”);
Context context = new VelocityContext();
context.put("DAT", "");
writer=new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream("PACKAGE+新文件名"),charSet)));
template.merge(context, writer);
writer.flush();
writer.close();
} catch (Exception e) {
}
参照:
a) 创建Velocity 引擎(VelocityEngine)并设置属性.
b) VelocityContext 高低文对象创建于设置.
c) 应用VelocityEngine(Velocity 引擎)创建模板(Template).
d) 归并模板和高低文对象、输出.
using System;
using System.Web;
// NVelocity 引用
using NVelocity;
using NVelocity.App;
using NVelocity.Runtime;
publicclass ShowHTML : IHttpHandler
{
publicvoid ProcessRequest(HttpContext context)
{
// 1.创建Velocity 引擎(VelocityEngine)并设置属性
VelocityEngine velocityEngine=new VelocityEngine();
velocityEngine.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file");// Velocity加载类型
velocityEngine.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,// Velocity加载文件路径
context.Server.MapPath("~/Template/"));
velocityEngine.AddProperty(RuntimeConstants.INPUT_ENCODING, "gb2312");// 输入编码格局设置
velocityEngine.AddProperty(RuntimeConstants.OUTPUT_ENCODING,"gb2312");// 输出编码格局设置
velocityEngine.Init();
// 2.Velocity 高低文对象设置
VelocityContext vc=new VelocityContext();
// 页面参数设值
vc.Put("Name","MT!");
System.Collections.Generic.List<String> list =new System.Collections.Generic.List<string>();
for (int i =1; i<11; i++)
{
list.Add("My Name Is :"+ i);
}
vc.Put("list", list);
// 3.创建模板(Template)
Template template= velocityEngine.GetTemplate("default.html");
// 4.归并模板和高低文对象、输出
template.Merge(vc, HttpContext.Current.Response.Output);
HttpContext.Current.Response.End();
}
- 使用VELOCITY生成文件
- spring velocity生成静态文件
- 使用velocity生成静态页面,及velocity的循环控制
- 使用Spring计时器和velocity模板定时生成静态html/jsp文件
- 使用 Velocity 模板引擎快速生成代码
- 使用Apache Velocity生成HTML报表
- 使用 Velocity 模板引擎快速生成代码
- 使用 Velocity 模板引擎快速生成代码
- 使用 Velocity 模板引擎快速生成代码
- 使用 Velocity 模板引擎快速生成代码
- 使用 Velocity 模板引擎快速生成代码
- 使用 Velocity 模板引擎快速生成代码
- 使用 Velocity 模板引擎快速生成代码
- 使用 Velocity 模板引擎快速生成代码
- Velocity中使用Struts的国际化文件
- Velocity中使用Struts的国际化文件
- velocity基础教程--4通过velocity生成文件--网站静态化实现方案
- velocity基础教程--4通过velocity生成文件--网站静态化实现方案
- SQL中使用xp_cmdshell将硬盘中文件内容导入数据库
- Android RenRen SDK 接入教程
- 第5章表达式运算符
- arm11处理器架构详细分析
- js 对cookie的设置 删除 获取
- 使用VELOCITY生成文件
- Job的任务执行流程之JobSetup阶段
- jquery选择器之简单选择器
- sql server中得到刚插入记录对应的自增列的值
- 第五周 任务二
- 业务日志之日志写入
- 第五周实验报告1
- 移动计费系统学习(二)
- [MOC062066]ubuntu11.10安装java JDK6.0