日期:2011-09-28  浏览次数:20809 次

ASP的强大不仅仅局限于接受和显示的交互,更多的是运用ActiveX 组件进行更强大的Web应用。

那究竟ActiveX组件为何物?它又是如何运作的呢?其实ActiveX Server Components(ActiveX 服务器组件)是一个存在于 WEB 服务器上的文件,该文件包含执行某项或一组任务的代码,组件可以执行公用任务,这样就不必自己去创建执行这些任务的代码。很形象的一句话:运用组件直接采用别人经典的功能强大的程序。只不过这程序已被封装了的。

那具体ActiveX组件是如何产生、如何得来的呢?一般由下面三个路径获得:
1,安装完IIS服务器以后,自带的一些内置组件,如Database Access数据库连接组件。
2,从第三方开发者处获得可选的组件,或者免费或者收费的,如一些上传组件(当然现在有无组件上传)。
3,如果你是一位Web程序开发者,可以使用Visual Basic 、Java 、Visual C++ 、COBOL等程序设计语言来编写你所需要的ActiveX Server Component。这也就是所谓的ASP进行COM(Component Object Model)、COM+开发了。

当然无论是第三方还是自行开发,在使用之前都必须要进行系统的注册。不过这些都是后话。我们现在需要的,是尽快先把ASP自带的一些组件搞懂吧。

不过在使用内置组件之前,先用一个程序检测一下自己机器中的组件支持情况。
引用一段网上流行的“阿江ASP探针”,将下列代码保存为asp文件进行调试查看。

1,objcheck.asp

<%Option Explicit %>
<%
Dim filename
filename=Request.ServerVariables("SCRIPT_NAME")

Dim ObjTotest(14,4)
ObjTotest(0,0) = "MSWC.AdRotator"
ObjTotest(0,1) = "广告轮显组件"
ObjTotest(1,0) = "MSWC.ContentRotator"
ObjTotest(1,1) = "内容轮显组件"
ObjTotest(2,0) = "MSWC.BrowserType"
ObjTotest(2,1) = "浏览器类型显示组件"
ObjTotest(3,0) = "MSWC.NextLink"
ObjTotest(4,0) = "MSWC.Tools"
ObjTotest(5,0) = "MSWC.Status"
ObjTotest(6,0) = "MSWC.Counters"
ObjTotest(7,0) = "MSWC.IISLog"
ObjTotest(8,0) = "MSWC.PermissionChecker"
ObjTotest(9,0) = "Microsoft.XMLDom"
ObjTotest(10,0) = "IISSample.ContentRotator"
ObjTotest(11,0) = "IISSample.PageCounter"
ObjTotest(12,0) = "Scripting.FileSystemObject"
ObjTotest(13,0) = "adodb.connection"

public IsObj,VerObj,TestObj

dim i
for i=0 to 13
on error resume next
IsObj=false
VerObj=""
TestObj=""
set TestObj=server.CreateObject(ObjTotest(i,0))
If IsObject(TestObj) then
IsObj = True
VerObj = TestObj.version
if VerObj="" or isnull(VerObj) then VerObj=TestObj.about
end if
ObjTotest(i,2)=IsObj
ObjTotest(i,3)=VerObj
next

sub ObjTest(strObj)
on error resume next
IsObj=false
VerObj=""
TestObj=""
set TestObj=server.CreateObject (strObj)
If IsObject(TestObj) then
IsObj = True
VerObj = TestObj.version
if VerObj="" or isnull(VerObj) then VerObj=TestObj.about
end if
End sub
%>
<title>Object Check</title>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#cccccc" width=80%>
<tr align=center><td width=40%>组 件 名 称</td><td width=40%>相 关 信 息</td></tr>
<%For i=0 to 13%>
<tr>
<td> <%=ObjTotest(i,0) & " <font color=#888888>" & ObjTotest(i,1)%></font></td>
<td> 
<%
If Not ObjTotest(i,2) Then
Response.Write "<font color=red>不支持</font>"
Else
Response.Write "支持," & left(ObjTotest(i,3),22)
End If%></td>
</tr>
<%next%>
</table>

<FORM action=<%=filename%> method=post>
<input type=text name="classname" size=40>
<INPUT type=submit value=" 确 定 ">
</FORM>

<%
Dim strClass
strClass = Trim(Request.Form("classname"))
If strClass <> "" then
Response.Write "<br>您指定的组件的检查结果:"
Dim Verobj1
ObjTest(strClass)
If Not IsObj then
Response.W