当前位置: 首页 > news >正文

小程序网站开发者利/长沙做搜索引擎的公司

小程序网站开发者利,长沙做搜索引擎的公司,天津铁路建设投资控股(集团)网站,个人网站起个名字首先:在Castle Project上下载一个CastleProject包,我下载的是CastleProject-1.0-RC3.msi安装后,在其下的bin目录中可找到NVelocity.dll(NET项目中将用到),并将其复制出来放到我的测试WEB/BIN目录下。到castleproject上…

首先:在Castle Project上下载一个CastleProject包,我下载的是CastleProject-1.0-RC3.msi
安装后,在其下的bin目录中可找到NVelocity.dll(NET项目中将用到),并将其复制出来放到我的测试WEB/BIN目录下。
到castleproject上看了一下using it大致有四步:
先要引入以下名称空间:
using Commons.Collections;
using NVelocity;
using NVelocity.App;
using NVelocity.Context;
using NVelocity.Runtime;

第一步:Creating a VelocityEngine也就是创建一个VelocityEngine的实例
VelocityEngine velocity = new VelocityEngine(); //也可以使用带参构造函数直接实例。
ExtendedProperties props = new ExtendedProperties();
velocity.Init(props);

第二步:Creating the Template加载模板文件
这时通过的是Template类,并使用VelocityEngine的GetTemplate方法加载模板
Template template = velocity.GetTemplate(@"path/to/myfirsttemplate.vm");

第三步:Merging the template整合模板
VelocityContext context = new VelocityContext();
context.Put("from", "somewhere");
context.Put("to", "someone");
context.Put("subject", "Welcome to NVelocity");
context.Put("customer", new Customer("John Doe") );

第四步:创建一个IO流来输出模板内容。推荐使用StringWriter(因为template中以string形式存放)
StringWriter writer = new StringWriter();
template.Merge(context, writer);
Response.Write(writer.ToString());

---通过上述步骤就可以轻松的使用NVelocity模板引擎的技术了。
有没有发现最后的Response.Write(writer.ToString())?
这个是直接输入到页面上。如果我们不直接输出到页面上,而是把它写入到一个文件中呢?
生成静态页--是的,这是让大家都心动的。 
下面的代码是我第一个练习:
 

using Commons.Collections;
using NVelocity;
using NVelocity.App;
using NVelocity.Context;
using NVelocity.Runtime;
/**//// 
/// 这个测试是基于NVelocity模板引擎实现的.
/// 

public partial class NVelocity_模板引擎测试 : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
//创建NVelocity引擎的实例对象
        VelocityEngine velocity = new VelocityEngine();
        
//初始化该实例对象
        ExtendedProperties props = new ExtendedProperties();
        props.AddProperty(RuntimeConstants.RESOURCE_LOADER, 
"file");
          //可换成:props.AddProperty("resouce.loader","file"),以下的同道理
        props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, Path.GetDirectoryName(Request.PhysicalPath));
        props.AddProperty(RuntimeConstants.INPUT_ENCODING, 
"gb2312");
        props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, 
"gb2312");
        velocity.Init(props); 
        
//从文件中读取模板
        Template temp = velocity.GetTemplate("myTemplate.html");
        IContext context 
= new VelocityContext();
        context.Put(
"from""Sichuan");
        context.Put(
"to""hainan");
        context.Put(
"subject""welcome to nvelocity");
        context.Put(
"name""McJeremy");
        
//合并模板
        StringWriter writer = new StringWriter();
        
//velocity.MergeTemplate(context, writer);
        temp.Merge(context, writer);
        
//输入
        Response.Write(writer.ToString().Replace("\r\n""
"));
    }
    
}
以下是生成静态页的练习:
using Commons.Collections;
using NVelocity;
using NVelocity.App;
using NVelocity.Context;
using NVelocity.Runtime;
/**//// 
/// 这个测试是基于NVelocity模板引擎实现的.
/// 
public partial class NVelocity_模板引擎测试 : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
//创建NVelocity引擎的实例对象
        VelocityEngine velocity = new VelocityEngine();
        
//初始化该实例对象
        ExtendedProperties props = new ExtendedProperties();
        props.AddProperty(RuntimeConstants.RESOURCE_LOADER, 
"file");
        props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, Path.GetDirectoryName(Request.PhysicalPath));
        props.AddProperty(RuntimeConstants.INPUT_ENCODING, 
"gb2312");
        props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, 
"gb2312");
        velocity.Init(props); 
        
//从文件中读取模板
        Template temp = velocity.GetTemplate("myTemplate.html");
        IContext context 
= new VelocityContext();
        context.Put(
"from""Sichuan");
        context.Put(
"to""hainan");
        context.Put(
"subject""welcome to nvelocity");
        context.Put(
"name""McJeremy");
        
//合并模板
        StringWriter writer = new StringWriter();
        
//velocity.MergeTemplate(context, writer);
        temp.Merge(context, writer);
        
//生成静态页
 using (StreamWriter writer2 = new StreamWriter(Server.MapPath("/"+ "test.html"), false, Encoding.UTF8, 200))
        
{
            writer2.Write(writer);
            writer2.Flush();
            writer2.Close();
        }


    }
    
}

转载于:https://www.cnblogs.com/yasin/archive/2010/04/02/1703110.html

http://www.lbrq.cn/news/1381393.html

相关文章:

  • 什么是网站架构/网站友情链接怎么弄
  • 电影vip免费网站怎么做的/小程序开发模板
  • 黑河北京网站建设/高权重外链
  • 1核1g可以做几个网站/优化设计官方电子版
  • 成都旅游十大必去景区/广东网站优化公司
  • 自己做网站导航/百度权重是什么意思
  • 长沙公司做网站/如何获取网站的seo
  • 17我们一起做网站/微信朋友圈广告投放
  • 南昌建站方案/详情页设计
  • 网站加友情链接/推广竞价账户托管
  • 做网站啦代理的方法/电商运营数据六大指标
  • 陕西网站建设通报/网站技术解决方案
  • 七里河微信网站建设/百度双十一活动
  • 用nas做网站/企业seo排名哪家好
  • 学校网站群建设思路/游戏优化大师下载安装
  • php网站开发wamp/宁波seo关键词费用
  • 网站客户体验/seo难不难学
  • 武汉网站制作成功案例/网络营销岗位有哪些
  • 做响应式网站怎么设计/对网络推广的理解
  • 山东网站建设哪家好/百度关键词优化软件排名
  • 建网站卓/外链网
  • 建设银行网站修改手机号码/搜索引擎优化的主要工作
  • 做网站赚钱不/网站建设品牌公司
  • 句容网络公司/seo外链购买
  • 如何来建设网站/代写文章哪里找写手
  • 注册网站域名有什么用/产品如何做网络推广
  • 网站建设中最基本的决策/怎么样优化网站seo
  • 南宁横县网站建设推广/app推广方式有哪些
  • 自动生成图片的网站/个人网站免费推广
  • 推广的注意事项/seo管理与优化期末试题
  • 【LeetCode 热题 100】394. 字符串解码
  • 从内部保护你的网络
  • 在SQL SERVER 中,用SSMS 实现存储过程的每日自动调用
  • 如何创建一个飞书应用获取自己的飞书AppID和AppSecret?
  • 逻辑回归----银行贷款模型优化
  • 从O(n²)到O(n log n):深度剖析快速排序的内存优化与cache-friendly实现