Programming for ASP Server components

Source: Internet
Author: User
Tags exit integer web database
Programming | Server Chongqing publishing House Computer Center Chen
1. What is an ASP server component

ASP (Active Server page) is the most powerful technology for developing interactive Web pages and Web database applications today. In which you can mix HTML, DHTML,
ActiveX, VBScript, or JavaScript. When none of these technologies work (e.g., high density mathematical operations, encapsulation of specific database processing logic)
, etc.), you can further extend the capabilities of the ASP by using the server component (Sidecomponent).
The server sidecomponent is actually a DLL running on the server that can accomplish any task that a regular DLL can do. The difference is: it's made up of
ASP page calls, and the Web page as the interactive object, read into the user's input (the value of the input fields on the Web page), processed to return the results to the Web page. These
Interaction is, of course, mediated by a Web server. Can use VB, VFP, VC + +, C++builder, Delphi and so on any support of the language of COM technology to write. Because
It can take advantage of any resource on the server and its functionality is limited by your imagination.
Currently, the Web server that supports ASP has IIS (Internet information server,winnt Server4.0) and PWS (personel Web server,
for WIN95 environments). and requires the server Components:frontpage server Extensions in the Visualinterdev installation, Active
Serverpages and client components:visual interdevclient. This can be installed on the same machine, so that it can be convenient on a single computer
To programming, debugging.
The following uses VB5.0 to develop a server Side Component (a activexdll) to implement a random graphical display on a Web page, and believe it will stand for you
The point is much more.

2. Random graphic display on a Web page

A nice graphic can make a Web page more appealing and fascinating. But once our web page design is complete, the graphic is determined. Change
In other words, unless we rewrite the HTML code, every time we open the page, we see the same graphic. So is it possible for users to enter our
Site, you can see a different picture? For example: Every time this web page is accessed, randomly select one from a folder that contains several graphic files
Displayed on this page, so that users who visit the page will get different visual enjoyment each time.
This requirement is not possible with HTML, DHTML, or VBScript languages, which we implement with an ASP server component.

3. To build an ActiveX DLL with VB5.0

First create a new project in VB5.0, the type is an ActiveX DLL: Set the properties as follows:
Project Name:randshowfile,
Classmodule Name:randimage
The code for the class Randimage is as follows:
Option Explicit
Private Mvarfilepath as String ' local copy
Public Property Let FilePath (ByVal vdata as String)
' Set file path
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
' Get file path
FilePath = Mvarfilepath
End Property

Private Sub Class_Initialize ()
Mvarfilepath = ""
End Sub

Public Function Show (Optional ByVal Extension As String) as String
' Randomly select and return a filename from the specified file path
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 = ' *.* ' If the extension is not specified, the default is *.*
End If
MyPath = Mvarfilepath & Trim (Extension) ' Set the path.
MyName = Dir (MyPath vbnormal) ' Retrieve '
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 ' Initialize the rand () function, or it will produce the same number each time
n = Int (FileCount * RND ()) ' produces a random number between 1 and List1.listcount.
Show = List (n)
Erase List
Exit Function
Else
Badnews:
Show = "Nofilefound"
Erase List
End If
End Function
Before compiling, note that you want to include a module in this project and add code to it
Sub Main ()
End Sub
Then in the menu project | Randshowfile projectise? Out of the dialog box, set startup
Object is sub Main. Finally, in the menu file, select Make Randimage.dll. To this, our SSC
The development is complete, and it is automatically registered on the machine.

4. Using server components in ASP pages

The following is an ASP page to test our server Side Component.
Start Visual InterDev, start a new project: New Projects, and then select Web Project Wizard, enter in Project name
Testrandimage, after clicking OK, Visual InterDev produces some auxiliary files, prepares for the new project, and then automatically opens the project. For convenience
Test, copy several graphics files to the images folder, the file type can be any browser-supported graphics files, such as BMP, TIF, GIF and so on.
Create ASP page in this project, click menu File | New, select Files in the New dialog box | Active Server Page and specify its name:
Randimage.asp. Visual InterDev will create an empty frame for us, in which code is added manually. The completed code is as follows

<%@ language= "VBSCRIPT"%>
<body>
<%=server.mappath ("Images")%><br>
<%set
Ox=server.createobject ("Randshowfile.randimage") ' Instantiate component Ox.filepath=serve
R.mappath ("Images")
%>

<%set ox=nothing ' release component after use%>
</body>
Because the path (URL) used by the Web page is a virtual path (fictitious Directory), you must convert it to a physical path using Server.MapPath ()
(Physical Directory). For example, the virtual path for the Graphics folder Images here is://servername/testrand Image/images, where
ServerName is the name of your Web server, and its corresponding physical path is C:\Inetpub\wwwroot\TestRandimage\Images. If you don't put
Images mapped to a physical path, the component cannot find the folder and does not function properly. After the code is finished testing, notice that every time you hit



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.