最近做了一個asp的購物網站,有點感想,分享下
1.和net不一樣的是裡面沒有那麼多個物件,基本上都是過程編程,利用到的對象有response,request,server
2.邏輯代碼地區使用<%%>負責
3.引用其他頁面或者邏輯處理代碼使用<!--#include file="xxxx.asp" -->
4.if,while,for等語句基本上都是if 條件 then 執行語句 end if
5.建立資料庫物件使用server.CreateObject("adodb.recordset")
6.定義對象類似var一樣,都是弱類型的,這裡採用vb文法dim來申明對象
下面是我的一個頁面的簡單代碼,可以說明上面這些問題
<!--#include file="Include/Conn.asp" --><!--#include file="Include/function.asp" --><!--#include file="Include/md5.asp" --><%dim username,password,comeurlusername=replace(trim(request.Form("username")),"'","")password=md5(replace(trim(request.form("password")),"'",""),32)if trim(request.form("comeurl"))="" then comeurl="member.asp"else comeurl=trim(request.form("comeurl"))end ifif username="" or password="" then response.Write "<script LANGUAGE='javascript'>alert('登入失敗!請檢查您的登入名稱和密碼!');history.go(-1);</script>" response.endend ifset rs=server.CreateObject("adodb.recordset")rs.Open "select * from [User] where username='"&username&"' and password='"&password&"' " ,conn,1,3if not(rs.bof and rs.eof) then if password=rs("password") then response.Cookies("timesshop")("username")=trim(request.form("username")) rs("lastvst")=now() rs("loginnum")=rs("loginnum")+1 rs.Update rs.Close set rs=nothing call loginok() else response.write "<script LANGUAGE='javascript'>alert('登入失敗,請檢查您的登入名稱和密碼!');history.go(-1);</script>" end ifelse response.write "<script LANGUAGE='javascript'>alert('登入失敗!請檢查您的登入名稱和密碼!');history.go(-1);</script>"end ifsub loginok()response.Write "<font size=2>歡迎 <font color=red size=2>"&request.Cookies("timesshop")("username")&"</font>,光臨兩秒種後將自動跳轉到相應頁!</font>"response.redirect comeurlend subconn.closeset conn = nothing%>
一直都沒學過asp的文法,這次也是在原來的一個項目上做調整,也就是看一點學一點,花了一點時間算是搞定了,也對asp有了基本的瞭解。由於經常都是做net方面的對象編程,突然轉到過程編程上來還真有點不習慣