ASP僞靜態html實現方法

先聲明這東西是轉來的,因爲確實很有用....ASP僞靜態實現!現在到處都是靜態化網頁,因爲好處多多所以樂此不疲...下面看看代碼:

數據庫是access,表名article,裏面有id,title,content
config.asp連接數據庫文件
< %
'功能:asp實現僞靜態的例子
'數據庫鏈接
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="http://www.xxxx.com/article.asp?/< %=rs("id")% >.html">< %=left(trim(rs("title")),30)% ></a>< >
< %
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>

發佈了5 篇原創文章 · 獲贊 4 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章