网络编程
位置:首页>> 网络编程>> Asp编程>> ASP生成静态网页的方法(2)

ASP生成静态网页的方法(2)

  发布时间:2008-02-18 19:20:00 

标签:静态,html,数据库,asp

具体实现上又有这两种方法

1。管理后台添加记录时,直接生成目标html页面,并且前台调用连接直接指向生成的html页面。这种方法程优点是程序效率最高。服务器负荷轻,不过由于生成的是纯静态页面,一旦页面样式上有所改动就必须重新生成所有的内容页。所以实际使用中应用一般不是太多。更多的是使用js,ssi,xml/xsl等客户端手段,生成的静态文件中仅保存数据,不涉及样式,这样能达到速度和维护性的平衡,不过相对前后台程序要复杂些(应用这种方法时,由于内容为纯静态,可以搭配单独编译的纯静态的apache使用。。效率和资源占用上比包含动态内容支持的要更佳)

2。前台访问链接指向asp程序,asp程序首先检查是否存在相应的静态文件。如果静态文件不存在。则生成并重定向至此文件,否则直接重定向。这种方法实际使用中一般和apache的url_rewrite功能一起使用。将asp的文件地址重为html的形式,有利于搜索引擎的检索。这种方法在效率上略有损失,不过程序结构简单,便于调整,在访问量不是很大时使用很合适。。   


<% sub    addhtml()   
   sql="select    *    from    article    where    (articleid    is    null)"     
   rs.open    sql,conn,1,3   
   rs.addnew   
  
   rs("title")=title   
   rs("keys")=keys   
   rs("content")=content   
   rs("Nclassid")=Nclassid   
   rs("classid")=classid   
   rs("Nkey")=Nkey   
   rs("hits")=0   
   rs("state")="no"   
   rs("author")=session("admin")   
  
   if    request.form("writer")<>""    then   
   rs("writer")=trim(request.form("writer"))   
   end    if   
   if    request.form("writefrom")<>""    then   
   rs("writefrom")=trim(request.form("writefrom"))   
   end    if   
  
  
   rs("dateandtime")=date()   
   rs.update   
  
   articleid=rs("articleid")   
           '///////////按文件ID取得文件名   
   makefilename="node@nhgov"&    articleid    &    ".html"   
           '//////////////////////////////////   
   '按日期生成文件夹   
           'filepath=date()   
           'Set    fso    =    CreateObject("Scripting.FileSystemObject")   
           'if    Not    fso.FolderExists(server.mappath(filepath))    then   
           'Fso.Createfolder(server.mappath(filepath))   
           'end    if   
   'Set    fso    =    nothing   
   '/////////////////////////////////   
            
   '/////////////////////////////////   
   '//        By    kalen    At    2002/12/18          //   
   '/////////////////////////////////   
    
   '导入模板文件   
           filename    =    "node_news\template"   
           Set    MyFileObject=Server.CreateObject("Scripting.FileSystemObject")   
           Set    MyTextFile=MyFileObject.OpenTextFile(server.mappath(filename))   
           While    NOT    MyTextFile.AtEndOfLine   
           gut    =    MyTextFile.ReadAll   
           WEND   
           MyTextFile.Close   
    
           '加入模板参数   
   '/////////////////////////////////   
   dates=date()   
   gut=replace(gut,"Hits_id",articleid)   
   gut=replace(gut,"Date",dates)   
   gut=replace(gut,"Title",title)   
  
   if    request("htmlable")="yes"    then   
   contents=content   
   else   
   contents=replace(replace(content,chr(13),"<BR>"),"    ","&nbsp;")   
   end    if 
    
   gut=replace(gut,"Content_Test",contents)   
   gut=replace(gut,"keyword_Test",Nkey)   
   '/////////////////////////////////   
            
   '生成新文件   
   '/////////////////////////////////   
   Set    fso    =    Server.CreateObject("Scripting.FileSystemObject")   
           Set    fout    =    fso.CreateTextFile(server.mappath(filePath&    "\"    &    makefilename))   
           fout.WriteLine    gut   
           fout.close   
   '/////////////////////////////////   
   end    sub
   %>

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com