打印本文 打印本文  关闭窗口 关闭窗口  
Asp组件中级入门与精通系列
作者:龙卷风.NET  文章来源:csdn.net  点击数  更新时间:2006/4/22 23:09:04  文章录入:admin  责任编辑:admin

我们学习来看一下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文件


 

配置好虚拟目录,在ie中执行fc5.asp文件,可以看到

龙卷风
26
age: 26
username: 龙卷风
com_age: 26
com_username: 龙卷风
其中用户姓名是: 龙卷风
其中用户年龄是: 26

上一页  [1] [2] [3] [4] [5]  下一页

打印本文 打印本文  关闭窗口 关闭窗口