因為工作需要使用Nvelocity
首先建立一個hmtl頁面 然後添加 替換的腳本如紅色的部分
<!DOCTYPE html PUBLIC
<html xmlns=
<head>
<title></title>
</head>
<body>
$m $q
</body>
</html>
然後添加一個aspx 頁面 首先引用 Nvelocity
然後
using System;
using System
using NVelocity;
using NVelocity
using NVelocity
using NVelocity
using Commons
using System
using System
namespace loginDemo
{
public partial class Nvelocity : System
{
protected void Page_Load(object sender
{
}
//這個方法用於頁面合並後打印到前台頁面
void MergeTemplate()
{
//創建NVelocity引擎的實例對象
VelocityEngine velocity = new VelocityEngine();
//初始化該實例對象
ExtendedProperties props = new ExtendedProperties();
props
props
props
props
velocity
//從文件中讀取模板
Template temp = velocity
IContext context = new VelocityContext();
context
context
//合並模板
StringWriter writer = new StringWriter();
temp
//輸入
Response
}
//這個頁面用於再本地根據模板生成相應的 html文件
void WriterTemplate
{
//創建NVelocity引擎的實例對象
VelocityEngine velocity = new VelocityEngine();
//初始化該實例對象
ExtendedProperties props = new ExtendedProperties();
props
props
props
props
velocity
//從文件中讀取模板
Template temp = velocity
IContext context = new VelocityContext();
context
context
//合並模板
StringWriter writer = new StringWriter();
temp
//生成靜態頁
using (StreamWriter writer
{
writer
writer
writer
}
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/12480.html