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

ASP偽靜態頁簡單教程

編輯:關於ASP編程
 

很簡單的教程,獻給喜歡SEO的朋友們。把article.asp?logID=26 替換成article.asp?/a26.html。不需要通過iis+ISAPI_Rewrite做基於IIS的url rewrite ,現在就開始。
一、數據庫很簡單使用ACCESS,Data.mdb建立一個表Article,三個字段:ID,Title,Content;自動編號、標題、文章內容。
二、Config.asp
ASP/Visual Basic代碼
<%
’數據庫鏈接
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
%>

三、Default.asp
ASP/Visual Basic代碼
<!--#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
ASP/Visual Basic代碼
<!--#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