程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> ASP技巧 >> asp程序實現偽靜態的代碼

asp程序實現偽靜態的代碼

編輯:ASP技巧

靜態頁面是蜘蛛喜歡的,會得到蜘蛛經常光顧的,以至於網站上的內容會得到搜索引擎更多的收錄
這裡介紹一個ASP偽靜態的程序實現方法
數據庫是Access,表名article,裡面有id,title,content
config.ASP連接數據庫文件
< %
'功能:ASP實現偽靜態的例子
'網址:www.ASPprogram.cn
'來源:網絡

'數據庫鏈接    
db="data.mdb"   
Set conn = Server.CreateObject("ADODB.Connection")    
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)    
conn.open connstr
    If Err Then   
        err.Clear    
        Set conn = Nothing   
        Response.Write "數據庫連接出錯,請檢查連接字串。"   
        Response.End   
    End If
'定義新聞閱讀界面的讀取
Dim News_title,News_content    
Sub ReadNews()    
 set rs1=server.createobject("adodb.recordset")    
    sql1="select id,title,content from article where id="& ID    
    rs1.open sql1,conn,3,3    
    News_title=rs1("title")    
    News_content=rs1("content")    
rs1.close    
set rs1=Nothing   
End Sub  
% >

index.ASP新聞列表頁

< !--#include file="config.ASP"-- >    
<ol>    
< %    
Set rs=server.CreateObject("adodb.recordset")    
sql="select * from Article"   
rs.open sql,conn,1,1    
do while not rs.eof    
% >    
<li><a href="article.ASP?/< %=rs("id")% >.Html">< %=left(trim(rs("title")),30)% ></a></li>    
< %    
rs.movenext    
loop    
rs.close    
set rs=Nothing   
% >    
</ol> 

article.ASP新聞內容頁
< !--#include file="config.ASP"-- >    
< %    
id=request.QueryString("id")    
If id="" Then     
server_v40=Request.ServerVariables("QUERY_STRING")  
id=Int(replace(replace(server_v40,"/",""),".Html",""))    
End If     
Call ReadNews()    
% >    
<div>    
標題: <b>< %= News_title% ></b><br />    
內容: < %=News_content% >    
</div>
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved