Ӧ
COMPUTER APPLICATIONS
1999 19 10 Vol.19 No.10 1999



ASPʵWebҳϵͼʾ
¸
ժҪASPǽʽWebҳ桢WebݿӦõҪASPԽһչASPĹܡһASPʵWebҳϵͼʾ
ؼʡASPWebҳ棬ͼʾ
1ASP
ASPServer Side ComponentʵڷϵһDLLɳDLLʤεκ񡣲֮ͬǣASPҳáWebҳΪ󣬶û루Webҳϸֵ󷵻ؽWebҳ档
ЩȻҪͨWebΪн顣ASPVBVFPVC++C++ BuilderDelphi֧COMԱд÷κԴ书ܽ
Ŀǰ֧ASPIISInternet Information ServerWinNTServer 4.0ԴPWSPersonel Web ServerWin95ҪװVisual InterDevеServer ComponentsFrontPage Server Extensions Active Server PagesClientComponentsVisual InterDev Client԰Щװͬһ̨ϣڵϷر̡ԡ
2Webҳϵͼʾ
һƯͼοʹWebҳʹһǵWebҳɣͼҲȷ֮޸HTML룬ÿδҳ棬ĶͬһͼΡôܷûÿνǵվʱܿͬĻأ磬ÿWebҳ汻ʱһͼļļѡȡһڸҳʾʹʸҳûÿζõͬӾܡ
ҪHTMLDHTMLVB Script޷һASPʵ֮
3ASPʵ
VB5.0һActiveX DLLʵWebҳϵͼʾΪվɫ١
VB5.0ActiveX DLL
VB5.0½һProject ΪActiveX DLL 
趨£
Project NameRandShowFile
ClassModule NameRandimage
RandimageĴ£
Option Explicit
Private mvarFilePath As String local copy
Public Property Let FilePath
(ByVal vData As String)
ļ·
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 ClassInitialize()
mvarFilePath = ""
End Sub
Public Function Show(Optional ByVal 
Extension As String)
As String
ָļ·ѡȡһļ
Extensionָļչ
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 thefirst 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()
ÿνͬ
n = Int(FileCount * Rnd())
 1 list1.listcount ֮.
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ĶԻУStartup ObjectΪSub Mainڲ˵FileУѡMake Randimage.dllˣǵServer Side Component ͿɣԶעڻϡ
4ASPҳʹ÷
潫һASPҳԲǵServer SideComponent
Visual InterDevʼһµḶ́New ProjectsȻѡȡWeb Project WizardProject NameTestRandimageOKVisual InterDevһЩļΪµĹ׼ȻԶ򿪸ù̡Ϊ˷ԣͼļImagesļУļͿֵ֧ͼļGIFJPGBMPȡ
ڸùнASPҳ棬˵File | New New ԻѡFiles | Active Server Page ָ֣Randimage.aspVisual InterDevΪǲһյĿܣֹ롣ɺĴ£
<%@ LANGUAGE="VBSCRIPT" %>
<html>
<head>
</head>
<body>
<h5>randimage ʾһͼļ<h5>
ͼļ·: <%=server.mappath("images")%><br>
<%
set ox=server.createobject
("randshowfile.randimage")ʵ
ox.filepath=server.mappath("images")
%>
<img src="<%=ox.filepath&ox.show%>">
<%set ox=nothing ʹúͷ%>
</body>
</html>
Webҳʹõ·URL·VirtualDirectoryʹserver.mappath()ת·Physical Directory磬˴ͼļimages·ǣ//Servername/TestRandimage/ImagesServernameWeb֣Ӧ·C:\Inetpub\wwwroot\TestRandimage\Images Imagesӳ䵽·ҲļУ޷
ɺ֮ע⵽ÿδ򿪻ˢ¸ҳʱһͬͼʾ档
5Ч
ʹServer Side ComponentԴḻWebӦõĹܡ߱ЧʣHTMLVBScriptȲɵ񣻷װضҵ߼ȡJava AppletȣֱWeb Server ִУִнΪHTMLҳһصûˣû޷ֱĽԪֱӵHTMLԪأServer Side Componentִнȥ˸ӵAppletع̺û˵ִй̡
߼飺¸ա˶ʿʦҪоźŴͼϵͳ
ߵλġ죨400016
ո:1999-05-05(޸ĸ)
