Asp.net动态页面静态化之include和parse区别
来源:互联网 发布:淘宝宝贝排名软件 编辑:程序博客网 时间:2024/05/21 21:34
Asp.net动态页面静态化之include和parse区别
#include就是在模版中在将其他模版包括进来,就好比网站的头部,尾部,广告模版等等,这些内容都是相同的时候,就可以做成一个单独的模版供各处引用。
#parse的用法跟#include相类似,如果将上面的代码改成#parse之后,效果是一样的,#parse的特殊功能在于,它可以解析Nvelocity元素,比如,body.html 模版使用Nvelocity变量 $body ,如果使用#parse引用head.html和footer.html两个模版,则在head.html、footer.html模版中继续可以使用$body这个变量,而#include做不到,并且相关的Nvelocity元素(#foreach、#if)也不起效果,只能原样输出,所以#parse > #inclued。
c#代码
using System;using System.Collections.Generic;using System.Linq;using System.Web;using NVelocity;using NVelocity.App;using NVelocity.Runtime;namespace czbk{ /// <summary> /// Test 的摘要说明 /// </summary> public class Test : IHttpHandler { public void ProcessRequest(HttpContext context) { string show = "我是测试include 和parse的区别的"; context.Response.ContentType = "text/html"; VelocityEngine vltEngine = new VelocityEngine(); vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file"); vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/"));//模板文件所在的文件夹 vltEngine.Init(); VelocityContext vltContext = new VelocityContext(); vltContext.Put("show", show); Template vltTemplate = vltEngine.GetTemplate("self.htm"); System.IO.StringWriter vltWriter = new System.IO.StringWriter(); vltTemplate.Merge(vltContext, vltWriter); string html = vltWriter.GetStringBuilder().ToString(); context.Response.Write(html); } public bool IsReusable { get { return false; } } }}
other公共html网页
<span style="color:Red">我是通过include过来的,也可以通过parse过来</span><span style="color:Red">我是测试:$show</span>
使用include的self.html页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title></head><body>#include("others.htm")<br />=========华丽的分割线==============<br /></body></html>
效果如图:
使用parse的self.hrml页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title></head><body>#parse("others.htm")<br />=========华丽的分割线==============<br /></body></html>
效果如图
0 0
- Asp.net动态页面静态化之include和parse区别
- jsp页面中的静态include和动态include的区别
- 静态include和动态include的区别
- 动态include和静态include的区别
- 静态include和动态include的区别
- ASP.NET 动态页面静态化 比较
- 新名词:ASP.NET动态页面静态化
- asp.net动态页面静态化
- jsp之Include动态指令和静态指令的区别
- asp.net动态页面如何静态页面
- JSP,include,静态和动态的区别
- <jsp:include>和<%@include%>的区别,JSP动态include和静态include的区别
- jsp中静态include和动态include的区别
- JSP中静态include和动态include的区别
- jsp中静态include和动态include的区别
- jsp 静态include和动态jsp:include的区别
- JSP中动态include和静态include区别
- jsp中动态include和静态include的区别
- epoll使用详解(精髓)
- hdu 1028 Ignatius and the Princess III 【整数划分】
- 《剑指offer》练习
- get和set的作用
- 浅析线程及同步
- Asp.net动态页面静态化之include和parse区别
- 排序算法_C++(一)插入排序之直接插入排序
- 栈和堆的区别
- 津津的储蓄计划
- c++ primer plus 第七章-编程题7.13.5《求任意一个数的阶乘》
- ContentProvider实例
- HDU 2563 统计问题 (递推)
- Android 4.0.x 浏览器不触发 ontouchend 事件的bug
- 嵌入式软件开发概述(4.1)------嵌入式软件程序设计