Asp组件中级入门与精通系列之五
我們學習來看一下Response對象。其實我們前面的教程中一直都在使用這個對象的Write方法。
這里我們用Response對象設置cookie。
?
打開vb6,新建Activex Dll工程。工程名修改為fCom,類名修改為fZ5
引用“Microsoft Active Server Pages Object”對象庫。
創(chuàng)建兩個組件事件:OnStartPage以及OnEndPage
在事件OnStartPage中創(chuàng)建類ScriptingContent的一個引用。
實例化類ScriptingContent。
?
代碼如下:
Option Explicit
'對象的聲明
Dim myResponse As Response
Dim myRequest As Request
Dim myApplication As Application
Dim myServer As Server
Dim mySession As Session
?
??? '當組件被創(chuàng)建的時候會觸發(fā)這個事件
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
?
??? '當組件被銷毀的時候觸發(fā)這個事件
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文件,系統(tǒng)自動會注冊。
否則就手工注冊 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中執(zhí)行fc5.asp文件,可以看到
龍卷風
26
age: 26
username: 龍卷風
com_age: 26
com_username: 龍卷風
其中用戶姓名是: 龍卷風
其中用戶年齡是: 26
未完待續(xù)
轉(zhuǎn)載于:https://www.cnblogs.com/Athrun/archive/2008/03/28/1127660.html
總結(jié)
以上是生活随笔為你收集整理的Asp组件中级入门与精通系列之五的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html 行间距
- 下一篇: 慕课版软件质量保证与测试(第一章.课后作