Analysis of ASP built-in components

Source: Internet
Author: User
Tags first string
The content of this article is to use the ASP's ActiveX Server components (component).

First, Browser capabilities Component (browser capability component):

We know that different browsers may support different functions, such as some browsers support the framework, and some do not support it. With this component, you can check the capabilities of your browser to make your Web page compete for different browsers for different pages (such as displaying pages without frame for browsers that do not support frame). The use of this component is very simple, it should be noted that to properly use the component, you must ensure that the Browscap.ini file is the latest (in fact, each browser and its characteristics are listed in this file, you open it to see it), otherwise the result may be very far, As in the Win98 second Edition, the IE5.0 shown in the following example is Netscape. This file is typically located under the "Winntsystem32inetsrv" of the Web server, and the latest version can be downloaded to http://www.asptracker.com/or http://www.cyscape.com/browscap.

Example: wuf22.asp

<BODY>
' Note: The use of components is similar to objects, but components must be created before they can be used, and you do not have to create them before you can use the built-in objects.
<%set browscap=server.createobject ("MSWC"). BrowserType ")%>
Please wait a moment ...
<P>
<table border=1 cellpadding=10>
<TR><TD> Browser Type </TD><TD><%=BrowsCap.Browser%></TD></TR>
<TR><TD> Browser Version </TD><TD><%=BrowsCap.version%></TD></TR>
<TR><TD> whether to support form </TD><TD><%=BrowsCap.tables%></TD></TR>
<TR><TD> whether ActiveX controls are supported &LT;/TD&GT;&LT;TD&GT;&LT;%=BROWSCAP.ACTIVEXCONTROLS%&GT;&LT;/TD&GT;&LT;/TR >
<TR><TD> whether to support javaapplets</td><td><%=browscap.javaapplets%></td></tr>
<TR><TD> whether to support javascript</td><td><%=browscap.javascript%></td></tr>
<TR><TD> whether to support cookies</td><td><%=browscap.cookies%></td></tr>
<TR><TD> whether to support frames</td><td><%=browscap.frames%></td></tr>
<TR><TD> Operating System </TD><TD><%=BrowsCap.Platform%></TD></TR>
<TR><TD> whether to support vbscript</td><td><%=browscap.vbscript%></td></tr>
</TABLE>
<%set Browscap = nothing%>
</BODY>
</HTML>

Note: In this example we also touch the CreateObject method of the server object, Server.CreateObject is used to create an ActiveX component that has been registered on the server (note: There are other ways to create components). But don't forget to use "Set object = Nothing" to release resources in time, this should become a habit.

Second, the File access component

The file access component consists of FileSystemObject objects and TextStream objects that use FileSystemObject objects to create, retrieve, delete directories and files, while TextStream objects provide the ability to read and write files.

Instance wuf23.asp. Emphasis: Only through practice can deepen understanding, practice and comparison program running results is the best way to quickly master programming skills.

<%@ Language=vbscript%>
<% Option Explicit
' Note absolute path: c:inetpubhomeaspwuf23.asp home page path: c:inetpubhome
Dim Path, File, FSO, CTF, Str, strHTML, strnohtml

' Create FileSystemObject object FSO using the CreateObject method
Set FSO = Server.CreateObject ("Scripting.FileSystemObject")

Path = Server.MapPath ("test") ' Returns the physical directory of test (absolute path)
' For this example, the following sentence is exactly the same as the path returned above
' Path = Server.MapPath (' asp est ')
Response.Write Path & "<Br>"

If FSO. FolderExists (Path) = False Then ' determines if the folder exists
Fso. CreateFolder (Path) ' New folder
End If

File = Path & "Asptest.txt"
' Write file operation
If FSO. FileExists (file) = True Then ' Determines if the file exists
' Establish TextStream object CTF
Set CTF = FSO. OpenTextFile (file, 8, False, 0) ' open files, as described in
Else
Set CTF = FSO. CreateTextFile (File,false, False) ' new file
End If
Ctf. Write "<P> first string;" ' Write String
Ctf. WriteLine "second string;" ' Write String, and add a newline character
Ctf. Write "a third string;"
Ctf. Close ' Note the file to be closed

' Read File operation
Set CTF = FSO. OpenTextFile (File, 1,,0)
Do While CTF. AtEndOfStream <> True ' to determine whether the end of a file (circular statement)
STR = CTF. ReadLine ' (every time) read one line
strnohtml = strnohtml & Str & "<BR>" & VbCrLf
strhtml = strhtml & Server.HTMLEncode (STR) & "<BR>" & VbCrLf
Loop
Response.Write strnohtml
Response.Write strHTML

Ctf. Close
Set CTF = Nothing ' Frees objects
Set FSO = Nothing
%>

CTF = FSO. OpenTextFile (File, 8, False, 0), the first argument in parentheses is the file name, the second argument is 8, the append content is appended to the original file, if 1 is read-only, 2 overrides the original file, and the third argument False indicates that if the specified file does not exist, the file is not created. If true to indicate that the specified file does not exist, the new file is created, and the fourth argument 0 is opened in the ASCII file format and, if-2, it is opened in its original format.

CTF = FSO. CreateTextFile (File,false, False), and the second argument false indicates that the existing file is not overwritten, and if true, the existing file is overwritten (OverWrite), and the third argument to false indicates that the file format is ASCII. True to indicate that the file format is Unicode.

The MapPath method of the server object converts the specified virtual path to a true file path. MapPath the "/" and "" characters as the same.

The HTMLEncode method of the server object allows you to HTML-encode a particular string, or to allow a specific character to be displayed correctly in the browser. In the example above, if not encoded, "<P>" is not displayed, but the browser as HTML tag, you can compare the results of the run.

In fact, the file access component is more powerful for files, folders, and drives, and it provides a number of ways to do this, and don't forget to use it if you need this knowledge.

In addition, to date, writing a web counter is a piece of cake, it is no wonder that so many pages provide free counters. What do you think? I write a graphics counter to try, how to cheat on how to cheat, complete their own decisions, cool stay! (Little secret: My homepage has an instance of wuf24.asp)

Third, Ad Rotator (Advertisement turnover component)

Now on the Internet, I am afraid that the most annoying is the other people on the homepage of the advertising bar, favorite is their own homepage on the ads, ads like spam, everywhere, impossible to guard against. You can also make such rubbish by yourself, the ASP's Ad Rotator component allows you to randomly display ads each time you open or reload a Web page. This example consists of three parts:

Routine W



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.