16. Other commonly used AX components

xiaoxiao2021-03-06  37

When you write a server-side application with ASP, you must rely on the functionality of the ActiveX component to power the web application, such as: You need to connect the database, perform online operation on the database, and more.

The two authors introduced you to the use of the use of the AD Rotator, Database Access, Today, we will then look at other ASP common components.

1. Browser Capabilities components are well known, not all browsers support all aspects of Today's Internet technology. There are some features, some browser supports and other browsers do not support, such as: ActiveX controls, image streams, dynamic HTML, Flash, and scripts. With ASP's Browser Capabilities component, you can design a "smart" web page to fit content in the format of the browser performance. Browser Capabilities Components Create a Browsertype object that provides a user script with a functional description with a client web browser. The component can identify information such as the version of the client browser, mainly because when the customer browser sends a page request to the server, the title is a USER Agent HTTP title, which is a declarative browser and its version of ASCII characters. string. The Browser Capabilities component maps the user agent to the browser indicated in the file browscap.ini, and identifies the client browser through the properties of the Browsertype object. If the object does not find items matching with the title in the browscap.ini file, the default browser properties will be used. If the object does not find a match and the default browser settings are not specified in the browscap.ini file, it sets each attribute to a string "unknown". By default, the browscap.ini file is stored in Windows / System / INERSRV (if it is 95/98 pws4) or NT / System32 / INERSRV (if it is NT) directory, you can edit this text file yourself to add Your own properties or modify the file based on the updated file of the latest browser version. Please see the following checkcookie () procedure, use the BrowserCap object's cookie property to determine if the client browser supports cookie and return information:

<%

Sub Checkcookie ()

Set browsercap = server.createObject ("mswc.browsertype")

if Browsercap.cookie = True Then

Response.write "Your browser supports cookie!"

Else

"Sorry, your browser does not support cookie!"

END IF

End Sub

%>

For more information on Browser Capabilities components, see Dynamic Website Design Eighteen Wood --ASP (2).

Second, File Access Components If your network age is large enough, you must have seen the "Dinosaur Age" CGI message book, which is the earliest prototype of the web message board. At that time, INTERNET-based web applications is also very difficult to connect the server backend database, so historical information in the message book is not stored in the backend database. So where is these data saved? The answer is "text file", the CGI program can write information received from the client to a text file stored in the server side, which can be a file such as an HTML file or txt, which makes the programmer not passing the same database. Connection can save customer information, but write such a CGI program is very cumbersome, the simplest sample of such programs is listed: #! / Usr / local / bin / perl

# Perl location one your server

Print "Content-Type: Text / Plain / N / N";

IF ($ env {'request_method'} EQ "pos") {

READ (stdin, $ buffer, $ env {'content_length'});

} Elsif ($ env {'request_method'} EQ "get") {

$ buffer = $ env {'query_stirng'};

}

@ Pairs = Split (/ & /, $ buffer);

Foreach $ pair (@pairs) {

($ Name, $ Value) = Split (/ = /, $ pair);

$ value = ~ Tr / //;

$ value = ~ s /% ([A-F A-F 0-9]) / PACK ("C", HEX ($ 1)) / EG;

$ Form {$ Name} = $ value;}

$ file_name = "guestbook.txt"; # file name

#details

Open (file, ">> $ file_name") || DIE "Opens File Error";

Print file "Record Time": $ DATE / N / N ";

Print file "Name": $ form {'name'};

Print File "Unit": $ form {'company'} / n ";

Print File "Phone": $ form {'phone'}

Print File "Address": $ form {'address'} / n ";

Print File "Zip Code": $ form {'zip'}

Print file "email address": $ form {'email'} / n ";

Print File "Back": $ form {'content'}

Close (file)

Everyone can feel that it is poor than the ASP readability and easy operationality of this CGI program. Then you must ask if the ASP can also write files directly on the server? The answer is of course affirmative. But smart friends may think that since the ASP is so convenient to connect with the web database, what do we need to write customer information in a text file? Is this function of ASP not to add a snake? Indeed, for those of our common message books, BBS and other web applications, whether it is in the execution efficiency or ease of use, we cannot replace the database with write text files, but in some web applications Write a text file in the field is both a specification and a relatively easy way. If you are more familiar with NT, you must know that NT has a very powerful security mechanism. It can automatically save almost all server operations and connections to files in a vectors called .log, in fact, this technology is also complete Can be used on the web to record some customer login information. The following program is using the feature of the ASP read and write text files, and creates the function of automatically recording each user's speech record in a web BBS program. <%

Set fs = creteObject ("scripting.filesystemobject")

Forreading = 1

'Open the file in read-only mode. This file cannot be written.

FORAPPENDING = 8

'Open the file and write it at the end of the file.

TristateuseDefault = -2

Tristatetrue = -1

Tristatefalse = 0

'----------- Write system log start --------

ServerMap = server.mappath ("/ bbs / log /")

'Mapping system physical path

Temp = ServerMap & "& Year (Date) & Month (Date) &" / "

'Get the system physical path and time, and use this as a physical path stored by the log file

IF not fs.folderexists (temp) THEN

fs.createfolder (TEMP)

END IF

'Detecting a folder existing, otherwise automatically creates

Dim syslog

DIM TEMPNAME

TempName = DATE

Syslog = TEMP & TEMPNAME & ". Log"

'File name E: / BBS / LOG / month / month .log

LI = User & "&" & "&" & "&" & TEMPFILE & "&" & "&" & "&" & "&" & ti "& tits

The format of 'log file record is: Username & Send Time & User IP & File Path & News District & Letter Title

IF fs.fileexists (syslog) THEN

Set ss = fs.opentextfile (syslog, forepaplending, true)

Else

Set ss = fs.createtextfile (syslog, forting, false)

END IF

'Detecting a log file exists, if there is an additional file content, then write a file directly

ss.writeline (li)

ss.close

'----------- Log file end ---------%>

If you don't understand this program above, please listen to it slowly. The File Access component provides methods and properties available to access computer file systems. We can use the File Access component to create a FileSystemObject object, the first sentence of the above programs is to create an object instance called FS using the FILE Access component. Once the object is created, you can access the file by it, the object is not attribute, its unique meaning is to create, open, or read and write text files. The FileSystemObject object has two most common methods, one for creating a file, the other is to open and read and write text files. The CreateTextFile method gets the file name you specified and creates the file. It returns a TextStream object, you can use the object to create the file after the file is created, the syntax of the CreateTextFile method is as follows:

Set objtextStream = filesystemObject.createteTextFile (filename, [overwrite], [unicode])

Below the author explains the parameters of the CreateTextFile method

1. FileName contains a string of file path names, which can be a full path name of the file, including the drive name and directory name, or only the file name. If only the file name is included, the file will be created under the root of the site.

2, OVERWRITE BUR, can prevent the FileSystemObject object from delete the existing file when you create a new file, which is optional when you create a new file. If you do not assign the system defaults to true, the existing file with the same file name Be deleted.

3, Unicode optional parameters. The Boolean value indicates whether a file is created in a Unicode or ASCII file format. If you create a file in a Unicode file format, this value is true; if the file is created in an ASCII file format, the value is false. If this section is omitted, the ASCII file is assumed.

In the previous program we use set ss = fs.createtextfile (syslog, forwriting, false) to create files in the case where the log file does not exist and write a file, "ForWriting" means a write file.

Unlike the CreateTextFile method, the OpenTextFile method is used to get the file name you specified and open the file. Using the parameters it takes to make a variety of different operations, like the CreateTextFile method, the OpenTextFile method returns a TextStream object, make You can do this file after the file is opened. The grammar of the OpenTextFile method is as follows:

Set objtextStream = filesystemObject.opEntextFile (filename, [omode], [create], [format])

The parameters are as follows:

1, FileName must be variable, FileName with CreateTextFile

2, Iomode optional constant, value for one of the following two constants forreading or forePpending, if the Mode is 1, the file is opened in a read-only mode, if it is 8, the file is opened in addition.

3, CREATE Optional Boolean, specified if the file you want to open does not exist, if its value is true, automatically creates an empty file when the file does not exist. If false, you will generate an error message when the file is not found, its default value is False, it is recommended to use it to True to avoid checking if it is opened when the file is opened. 4, Format optional value, you can select three Tristate values ​​to specify the format, -2, -1, and 0 respectively, respectively, respectively, respectively, Unicode, and ASCII, respectively.

After opening or creation of a text file, you get a TextStream object. This object has a cursor. Indicates the location of the characters you want to read. You cannot create a TextStream object with CreatObject, and the only way to get the TextStream object is to open an existing text file with the FileSystemObject object as described earlier or create a new file.

The properties and methods of the TextStream object are listed below.

TextStream.atendofline reads only Boolean quantity, when the cursor is at the end of the current line, its value is True, and it is false.

TextStream.atendofStream is read-only, if the cursor is at the end of the stream, it is true, otherwise false

TEXTSTREAM.COLUMN read-only integer, statistics from the number of characters between the leading to the current cursor position

TextStream.Line read-only integers, indicating the line number in the entire file in the cursor

TEXTSTREAM.CLOSE () Close the flow and the corresponding text file

TextStream.read (NUM) Specifies to start reading a certain number of characters from the text file from the current location of the cursor

TextStream.readall () Reads the entire stream into a string

TextStream.readLine () reads a string of characters in a string

TextStream.write (Text) Write a string into the stream

TextStream.writeline () Write a text string into the stream

TextStream.skip (NUM) In the stream, move the location of the cursor a certain number of strings

TEXTSTREAM.SKIPLINES () In the stream, move the cursor a certain number of rows

TextStream.writeblank will write a certain number of blank lines

Lines (NUM)

I believe that everyone can now feel the powerful features of the ASP File Access component. In fact, it can not only write some log files, and you can even automatically update your website through it. You only need to put the fixed format text. The file is transmitted to the remote server, read the file via the File Access component, and automatically generate a new HTML page without having to update the HTML file one by one. If you are interested, you can write a fully automatic HTML generator with the ASP's File Access component, fully enjoy the maintenance of the maintenance site.

转载请注明原文地址:https://www.9cbs.com/read-58007.html

New Post(0)