Asp元件中級入門與精通系列之六

2022-03-02 04:45:54 字數 2030 閱讀 5957

作為asp的內建物件,我們最後來學習server物件

server物件用的比較多的就是html編碼,url編碼和網頁的重定向,傳送。

?開啟vb6,新建activex dll工程。工程名修改為fcom,類名修改為fz6

引用「microsoft active server pages object」物件庫。

建立兩個元件事件:onstartpage以及onendpage

在事件onstartpage中建立類scriptingcontent的乙個引用。

例項化類scriptingcontent。

?**如下:

option explicit

'物件的宣告

dim myresponse as response

dim myrequest as request

dim myserver as server

dim mysession as session

???? '當元件被建立的時候會觸發這個事件

public sub onstartpage(myscriptingcontent as scriptingcontext)

???? '進行物件的例項化

???? set myresponse = myscriptingcontent.response

???? set myrequest = myscriptingcontent.request

???? set myserver = myscriptingcontent.server

???? set mysession = myscriptingcontent.session

end sub

???? '當元件被銷毀的時候觸發這個事件

public sub onendpage()

???? '銷毀物件

???? set myresponse = nothing

???? set myrequest = nothing

???? set myserver = nothing

???? set mysession = nothing

end sub

?public sub showhtml(byval strhtml as string)

??? myresponse.write myserver.htmlencode(strhtml)

end sub

?public sub showurl(byval strurl as string)

??? myresponse.write myserver.urlencode(strurl)

end sub

?public sub executeurl()

??? myserver.transfer "fz5.asp"

end sub

?編譯成dll檔案,系統自動會註冊。

否則就手工註冊 regsvr32 f:"test"fcom.dll?測試

開啟visual interdev6.0,生成乙個fz6.asp檔案

<%@ language=vbscript %>

<%

dim obj

set obj=server.createobject ("fcom.fz6")

obj.showhtml "

"response.write "

"response.write "name="

obj.showurl("mrs 龍捲風")

response.write "&age="

obj.showurl("26")

?response.write "

"call obj.executeurl ()

%>

?配置好虛擬目錄,在ie中執行fc6.asp檔案可以看到

name=mrs+%c1%fa%be%ed%b7%e7&age=26

可以使用ie的檢視原始檔來看html編碼??

?asp的內建物件就暫時介紹到這裡,後面我們還會陸續的學習。

大家也可以舉一反三,學習沒有介紹到的屬性和方法。

Asp元件中級入門與精通系列之七

開始資料庫操作。常見的元件封裝 1 把資料庫的連線資訊封裝起來。1 直接返回資料庫連線串,如,元件中 public?function?datasource as?variant datasource?driver server yang uid sa pwd database northwind e...

Asp元件中級入門與精通系列之七

開始資料庫操作。常見的元件封裝 1 把資料庫的連線資訊封裝起來。1 直接返回資料庫連線串,如,元件中 public?function?datasource as?variant datasource?driver server yang uid sa pwd database northwind e...

Asp元件中級入門與精通系列之七

開始資料庫操作。常見的元件封裝 1 把資料庫的連線資訊封裝起來。1 直接返回資料庫連線串,如,元件中 public?function?datasource as?variant datasource?driver server yang uid sa pwd database northwind e...