返回创远网络首页 | 台州创远网络 | 列表 >> 网络编程 >> 浏览主题 版主:
互联资讯 | 站长在线 | SEO搜索 | 网站运营 | 网络编程 | 全部分类
ASP生成静态Html文件的技术总结
已阅:3284 / 回复:1(楼主)
   把html代码写入到文件中然后生成.html格式的文件


     <%
  filename="test.htm"
  if request("body")<>"" then
  set fso = Server.CreateObject("Scripting.FileSystemObject")
  set htmlwrite = fso.CreateTextFile(server.mappath(""filename""))
  htmlwrite.write "<html><head><title>" request.form("title") "</title></head>"
  htmlwrite.write "<body>输出Title内容: " request.form("title") "<br /> 输出Body内容:" request.form("body") "</body></html>"
  htmlwrite.close
  set fout=nothing
  set fso=nothing
  end if
  %>
  <form name="form" method="post" action="">
  <input name="title" value="Title" size=26>
  <br>
  <textarea name="body">Body</textarea>
  <br>
  <br>
  <input type="submit" name="Submit" value="生成html">
  </form>


  2、但是按照上面的方法生成html文件非常不方便,第二种方法就是利用模板技术,将模板中特殊代码的值替换为从表单或是数据库字段中接受过来的值,完成模板功能;将最终替换过的所有模板代码生成HTML文件.这种技术采用得比较多,大部分的CMS都是使用这类方法.

  template.htm ’ //模板文件


<html>  
  <head>  
  <title>$title$ by aspid.cn</title>  
  </head>  
  <body>  
  $body$  
  </body>  
  </html>TestTemplate.asp ’// 生成Html  
  <%  
  Dim fso,htmlwrite
  Dim strTitle,strContent,strOut  
  ’// 创建文件系统对象  
  Set fso=Server.CreateObject("Scripting.FileSystemObject")  
  ’// 打开网页模板文件,读取模板内容  
  Set htmlwrite=fso.OpenTextFile(Server.MapPath("Template.htm"))  
  strOut=f.ReadAll  
  htmlwrite.close  
  strTitle="生成的网页标题"  
  strContent="生成的网页内容"  

  ’// 用真实内容替换模板中的标记  
  strOut=Replace(strOut,"$title$",strTitle)  
  strOut=Replace(strOut,"$body$",strContent)  

  ’// 创建要生成的静态页  
  Set htmlwrite=fso.CreateTextFile(Server.MapPath("test.htm"),true)  

  ’// 写入网页内容  
  htmlwrite.WriteLine strOut  
  htmlwrite.close  

  Response.Write "生成静态页成功!"  

  ’// 释放文件系统对象  
  set htmlwrite=Nothing  
  set fso=Nothing  
  %>


作者:admin (2009-10-12 9:48:55)
回复:ASP生成静态Html文件的技术总结
第 1 楼
stone processing equipment polishing machines bridge saw Profile machine cutting machinery stylaobte cutting machine stone machine automatic bridge cutter stone processing machine shaped piece cutter stone machinery stone machinery  automatic edge cutter cutting machine working center edge cutting machine drilling machine bridge cutting machine portal edge cutter single jib disk stone cutter oil-sealed cutter single pillar stone cutter two-way stone cutter  marble cutting machine square stone cutter infrared cutting machine double blade cutter gantry block cutter marble processing machine marble processing machine wire cutting machine granite processing machine multi-blade cutting machine stone cutter marble cutter sawing machine diamond wheel profiling wheel  saw blade external grinding internal grinding plane grinding planing block cutting machine cutting basin machine grinding and polishing machine Auto Cutting Machine Auto Cutting Machinery Edge cutting machinery Quarrying machine Quarrying machinery stone manufacturing equipment cutting equipment Stone Processing Machinery Equipment Stone Processing Machine Equipment Stone for industrial equipment cutter machine Stone cutting machine Stone Cutting Machinery Granite cutting Granite cutting machinery Granite cutting machine Marble cutting Marble cutting machinery stone equipment supplies automation stone manufacturing equipment polishing tools stone polishing tools Granite polishing tools Marble polishing tools stone polishing equipment stone industrial machines granite polishing equipment granite polishing machines bridge saws bridge saw granite diamond tools diamond tool diamond saws bridge saw machine bridge saw machinery saws stone cutting stone cutting saw bridge saws equipment profile cutting machine profile grinding machine profile wrapping machine Stripe Paving Stone Ceramics machine diamond saw bit experimental machine ceramic tile cutting machine stone engraving machine computer numerial controlling cutter stone worksite cutter
作者:stonemachi (2010-6-2 15:12:04)
当前总数:1 每页5条 当前1/1页 [1 

目前不允许游客回复,请 登录 注册 发贴.