ASP入门学习(一)准备阶段
Asp動態(tài)服務(wù)器頁面,是使用IIS部署運行的腳本語言。開發(fā)語言主要是VBScript語法。下面主要說說開發(fā)asp程序需要注意的地方和與數(shù)據(jù)庫連接的基本代碼格式,inc包含文件,函數(shù),過程定義,頁面編碼格式設(shè)置等。
一 準備工作
1.開發(fā)asp IDE軟件:推薦使用ASP Studio 版本1.45
2.設(shè)置IE腳本調(diào)試模式,方便查詢IIS拋出的服務(wù)器端錯誤信息,否則只會顯示簡單的Http 500 服務(wù)器內(nèi)部錯誤等。不方便程序的調(diào)試。
IE ->工具 ->Internet選項 ->高級 ->禁用腳本調(diào)試(Internet Explorer)不選(默認是選擇狀態(tài))。
3.IIS安裝,推薦安裝版本6.0。
開始 ->控制面板 ->添加或刪除程序 ->添加或刪除Windows組件 ->選擇Internet信息服務(wù)(IIS) ->下一步,直到安裝成功。
4.IIS設(shè)置。
開始 ->控制面板 ->性能和維護 ->管理工具 ->Internet 信息服務(wù)
1.創(chuàng)建虛擬目錄
?默認網(wǎng)站 ->右擊 ->新建 虛擬目錄
2.設(shè)置根目錄
?默認網(wǎng)站 ->屬性 ->主目錄(指定本地路徑)
?默認網(wǎng)站 ->屬性 ->網(wǎng)站(指定IP地址,提供本地局域網(wǎng)測試使用,默認為localhost,端口80)
3.瀏覽
?選擇需要瀏覽的頁面 ->右擊 ->瀏覽打開。
二 場景分析
查詢顯示數(shù)據(jù)庫中大類型和小類型信息,已菜單的格式顯示出來。ASP+Access數(shù)據(jù)庫。
三 代碼開發(fā)
inc.asp
<%'請在這里輸入您的ASP代碼response.Write("這一行是inc包含文件輸出的內(nèi)容!<br/>") %>conf.asp
<%'請在這里輸入您的ASP代碼'定義函數(shù)function TD_productsclass()TD_productsclass="這個是function函數(shù)定義返回值!<br/>"end function'定義過程sub ShowArticleContent()dim PaginationTypePaginationType=2select case PaginationTypecase 0 call DefaultPagination() '無內(nèi)容分頁格式case 1 call AutoPagination() '自動內(nèi)容分頁case 2 call ManualPagination() '按定義分頁end selectend subsub DefaultPagination()response.Write("sub無內(nèi)容分頁格式<br/>")end subsub AutoPagination()response.Write("sub自動內(nèi)容分頁<br/>")end subsub ManualPagination()response.Write("sub按定義分頁<br/>")end sub %>conn.asp
<% 'conn '準備工作 dim conn dim connstr dim path path = server.mappath("\OneFCMS_Data\OneFCMS.mdb") response.Write(path & "<br/>") 'on error resume next connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&path set conn=server.createobject("ADODB.CONNECTION") conn.open connstr If Err Thenerr.ClearSet Conn = NothingResponse.Write "數(shù)據(jù)庫連接出錯,請檢查數(shù)據(jù)庫連接文件中的數(shù)據(jù)庫參數(shù)設(shè)置。"Response.End End If %>index.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <%Response.CodePage=65001%> <%Response.Charset="utf-8"%> <!--#include file="inc.asp"--> <!--#include file="conf.asp"--> <!--#include file="conn.asp"--> <HTML> <HEAD><Title>index.asp</Title><META http-equiv="Content-Type" content="text/html; charset=utf-8"><META name="Generator" content="Asp Studio 1.0"> </HEAD><BODY><!-- 請在這里輸入您的HTML代碼 --> <%=TD_productsclass%> <%call ShowArticleContent()%> <%'請在這里輸入您的ASP代碼dim BigClassID '不能直接賦予值BigClassID = 5if not isnumeric(BigClassID) thenResponse.Write "<script>alert('警告!請勿嘗試注入!');history.go(-1);</script>" Response.End()end if'第一步:創(chuàng)建對象set rs1=server.CreateObject("adodb.recordset")'第二步:打開連接,執(zhí)行數(shù)據(jù)庫查詢語句rs1.open "select * from [bigClass] order by px_id asc",conn,1,1if rs1.eof and rs1.bof thenresponse.Write(" 暫無記錄 !")end if'第三步:判斷記錄集是否到達結(jié)尾if not rs1.eof then'第四步:數(shù)據(jù)的讀取和操作for i=1 to rs1.recordcount'查詢該大類下面的小類set rs2=server.createobject("adodb.recordset") exec="select * from [smallclass] where BigClassID="&rs1("BigClassID")&" order by px_id asc " rs2.open exec,conn,1,1 response.Write("<br/><a href='xxx?bigId=" & rs1("BigClassID") & "' title=" & rs1("BigClassName") &">" &rs1("BigClassName") & "</a>")'循環(huán)輸出該小類的信息'#################################do while not rs2.eofresponse.Write("<br/>---<a href='xxx?smallId=" & rs2("SmallClassID") & "' title=" & rs2("SmallClassName") & ">" & rs2("SmallClassName")& "</a>")rs2.movenextlooprs2.closeset rs2=nothing'#################################'response.Write("<br/>") rs1.movenext '大類移動到下一條。nextend if'第五步:數(shù)據(jù)庫對象的關(guān)閉和資源回收 rs1.closeset rs1=nothing %></BODY></HTML>?四 數(shù)據(jù)庫表
bigClass表
####################
1.BigClassID
2.BigClassName
3.px_id
####################
smallClass表
####################
1.SmallClassID
2.SmallClassName
3.BigClassID
4.px_id
####################
?
轉(zhuǎn)載于:https://www.cnblogs.com/simpledev/archive/2013/04/08/3006664.html
總結(jié)
以上是生活随笔為你收集整理的ASP入门学习(一)准备阶段的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: GitLab 发布全球开发者报告:开源仍
- 下一篇: 城市区号查询易语言代码