ASP(Active Server Page)是當(dāng)今開發(fā)交互式Web頁面、Web數(shù)據(jù)庫應(yīng)用最強大的技術(shù)。在其中可以混用HTML、DHTML、 ActiveX、VBScript或javaScript。當(dāng)這些技術(shù)都無法奏效時(例如進行高密度的數(shù)學(xué)運算、封裝特定的數(shù)據(jù)庫處理邏輯 等),可以使用服務(wù)器組件(Server SideComponent)進一步擴展ASP的能力。 Server SideComponent實際上是運行在服務(wù)器上的一個DLL,它可以完成常規(guī)DLL所能勝任的任何任務(wù)。不同之處是:它由 ASP頁面調(diào)用、并以Web頁面為交互對象,讀入用戶的輸入(Web頁面上各輸入域的值),處理后返回結(jié)果到Web頁面。這些 交互當(dāng)然都要通過Web服務(wù)器作為中介。可以用VB、VFP、VC++、C++Builder、Delphi等任意支持COM技術(shù)的語言編寫。由于 它可以利用服務(wù)器的任何資源,其功能僅受限于你的想象力。 目前支持ASP的Web服務(wù)器有IIS(Internet Information Server,WinNT Server4.0自帶)和PWS(Personel Web Server, 用于Win95環(huán)境)。并要求安裝VisualInterDev中的Server Components:FrontPage Server Extensions、 Active ServerPages和Client Components:Visual InterDevClient。可以把這些都安裝在同一臺機器上,這樣可以在單機上方便 地編程、調(diào)試。 下面用VB5.0開發(fā)一個Server Side Component(一個ActiveXDLL),以實現(xiàn)Web頁面上的隨機圖形顯示,相信它會為你的站 點增色不少。
首先在VB5.0中新建一個PRoject ,類型為ActiveX DLL :設(shè)定屬性如下: Project Name:RandShowFile, ClassModule Name:Randimage 其中類Randimage的代碼如下: Option Explicit Private mvarFilePath As String 'local copy Public Property Let FilePath(ByVal vData As String) '設(shè)置文件路徑 If Right(vData, 1) = "/" Or Right(vData, 1) = "/" Then mvarFilePath = vData Else If InStr(vData, "/") <> 0 Then mvarFilePath = vData & "/" Else mvarFilePath = vData & "/" End If End If End Property
Public Property Get FilePath() As String '取得文件路徑 FilePath = mvarFilePath End Property
Private Sub Class_Initialize() mvarFilePath = "" End Sub
Public Function Show(Optional ByVal Extension As String) As String '從指定文件路徑中隨機選取并返回一個文件名 Dim MyPath As String Dim MyName As String Dim List() As String Dim FileCount As Integer Dim n As Integer On Error GoTo badnews If Len(mvarFilePath) <= 1 Then Show = "NoFilePathSpecified " Erase List Exit Function Else If IsMissing(Extension) Then Extension = "*.*" '如果擴展名沒有指定,則默認為*.* End If MyPath = mvarFilePath & Trim(Extension) ' Set the path. MyName = Dir(MyPath, vbNormal) ' Retrieve the first entry. End If FileCount = 0 ReDim List(10) Do While MyName <> "" List(FileCount) = MyName FileCount = FileCount + 1 If FileCount >= UBound(List) Then n = UBound(List) + 10 ReDim Preserve List(n) End If MyName = Dir() Loop If FileCount >= 1 Then Randomize ' 初始化rand()函數(shù),否則每次將產(chǎn)生相同的數(shù)字 n = Int(FileCount * Rnd()) ' 產(chǎn)生在1 和list1.listcount 之間的隨機數(shù). Show = List(n) Erase List Exit Function Else badnews: Show = "NoFileFound" Erase List End If End Function 在編譯之前,注意要在此Project中加入一個Module并在其中加入代碼 Sub Main() End Sub 然后在菜單Project | RandShowFile Projectise?引出的對話框中,設(shè)Startup Object為Sub Main。最后在菜單File中,選Make Randimage.dll。到此,我們的SSC 就開發(fā)完成,并且它已自動注冊在機器上。
使用SSC可以大大豐富Web應(yīng)用的功能、提高編程效率;完成HTML或VBScript等不易完成的任務(wù);封裝特定的商業(yè)邏輯等。 Server Side Component(以及ActiveX)等組件的編程也發(fā)展成為一項有利可圖的事業(yè)。在Internet上可以找到很多有用 的組件(免費的或不免費的),有興趣者可到www.15seconds.com、www.activeserverpages.com、www.serverobjects.com 等站點上查看。如果你有一 個新穎有用的組件,也可以發(fā)表在這些站點上,說不定你可以因此得到一筆可觀的收入呢。