Asp組件中級入門與精通系列之五

來源:互聯網
上載者:User

我們學習來看一下Response對象。其實我們前面的教程中一直都在使用這個對象的Write方法。

這裡我們用Response對象設定cookie。

?

開啟vb6,建立Activex Dll工程。工程名修改為fCom,類名修改為fZ5
引用“Microsoft Active Server Pages Object”物件程式庫。
建立兩個組件事件:OnStartPage以及OnEndPage
在事件OnStartPage中建立類ScriptingContent的一個引用。
執行個體化類ScriptingContent。

?

代碼如下:

Option Explicit

'對象的聲明

Dim myResponse As Response

Dim myRequest As Request

Dim myApplication As Application

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 myApplication = myScriptingContent.Application

???? Set mySession = myScriptingContent.Session

End Sub

?

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

Public Sub OnEndPage()

???? '銷毀對象

???? Set myResponse = Nothing

???? Set myRequest = Nothing

???? Set myServer = Nothing

???? Set myApplication = Nothing

???? Set mySession = Nothing

End Sub

?

'從頁面中設定Cookie,組件中得到

Public Sub GetCookie()

??? Dim myitem

??? '全部資訊

??? For Each myitem In myRequest.Cookies

??????? myResponse.Write myitem & ": " & myRequest.Cookies.Item(myitem)

??????? myResponse.Write "
"

??? Next

???

??? '單個資訊

??? myResponse.Write "其中使用者姓名是" & ": " & myRequest.Cookies("username")

??? myResponse.Write "
"

??? myResponse.Write "其中使用者年齡是" & ": " & myRequest.Cookies("age")

??? myResponse.Write "
"

End Sub

'組件中設定cookie,頁面中得到

Public Sub SetCookie()

??? myResponse.Cookies("com_username") = "龍捲風"

??? myResponse.Cookies("com_age") = 26

??? myResponse.Expires = #9/13/2004#

End Sub

?

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

否則就手工註冊 Regsvr32 f:/test/fcom.dll

?

測試

開啟visual interdev6.0,產生一個fz5.asp檔案

dim obj

set obj=server.CreateObject ("fcom.fz5")

call obj.setcookie()

Response.Write Request.Cookies("com_username")

Response.Write "
"

Response.Write Request.Cookies("com_age")???

Response.Write "
"

?

'下面在頁面中設定Cookie

Response.Cookies("username") = "龍捲風"

Response.Cookies("age") = 26

call obj.GetCookie()

?

%>

?

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

龍捲風
26
age: 26
username: 龍捲風
com_age: 26
com_username: 龍捲風
其中使用者姓名是: 龍捲風
其中使用者年齡是: 26

未完待續

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.