Home  >  Article  >  Backend Development  >  ASP Knowledge Lecture 4_PHP Tutorial

ASP Knowledge Lecture 4_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 16:08:45886browse


ASP built-in components

In the first three lectures, we mainly introduced the four built-in objects provided by ASP:
l Response object: Send information to the browser.
l Request object: access information sent from the browser to the server (such as obtaining form data).
l Session object: stores and reads specific user conversation information.
l Application object: stores and reads application information shared by all users.
In addition, there are Server objects and ObjectContext objects that we will learn in future examples (hint: in fact, you can already use the knowledge you have learned to write an online chat room without realizing it). The content of this lecture is the use of ASP's ActiveX Server Components (components).

1. Browser Capabilities Component:
We know that different browsers may support different functions. For example, some browsers support frames and some do not. Using this component, you can check the browser's ability to make your web page display different pages for different browsers (such as displaying web pages without Frame for browsers that do not support Frame). The use of this component is very simple. It should be noted that to use this component correctly, you must ensure that the Browscap.ini file is up to date (in fact, every browser and its features are listed in this file. You will understand after opening it yourself. ), otherwise the results may be very different. For example, IE5.0 included in the second version of Win98 is displayed as Netscape in the following example. This file is generally located under "WinntSystem32InetSrv" on the Web server. The latest version can be downloaded from http://www.asptracker.com/ or http://www.cyscape.com/browscap.
Example: wuf22.asp


'Note: The use of components is similar to objects, but components must be created before use, but not before using built-in objects. create.
<%Set BrowsCap=Server.CreateObject("MSWC.BrowserType")%>
Please wait...









< /TR>

< TR>

Browser Type<%=BrowsCap.Browser%>
Browser Version<%=BrowsCap.version%>
<%=BrowsCap.tables%>
Whether it supports ActiveX controls< /TD><%=BrowsCap.activexcontrols%>
Whether JavaApplets are supported< ;%=BrowsCap.javaapplets%>
Whether JavaScript is supported<%=BrowsCap.javascript%> ;
Whether Cookies are supported<%=BrowsCap.Cookies%>
Whether Frames are supported<%=BrowsCap.Frames%>
Operating system<%=BrowsCap.Platform%>
Whether it is supported VBScript<%=BrowsCap.vbscript%>

<%Set BrowsCap = Nothing%>


Note: In this example we also touched the CreateObject method of the Server object. Server.CreateObject is used to create ActiveX components that have 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.

2. File Access component
File Access component consists of FileSystemObject object and TextStream object. Using FileSystemObject object, you can create, retrieve, and delete directories and files, while TextStream object provides the function of reading and writing files.
Example wuf23.asp. Emphasis: Only through practice can you deepen your understanding. Practicing and comparing program running results is the best way to quickly master programming skills.
<%@ Language=VBScript %>
<% Option Explicit
' Note the absolute path: C:Inetpubhomeaspwuf23.asp Home page path: C:Inetpubhome
Dim Path, File, FSO, CTF, Str, StrHTML, StrNoHTML

' Use the CreateObject method to create a FileSystemObject object FSO
Set FSO = Server.CreateObject("Scripting.FileSystemObject")

Path = Server.MapPath(" test") 'Return the physical directory (absolute path) of test
'For this example, the following sentence returns exactly the same Path as the above sentence
'Path = Server.MapPath("asptest")
Response.Write Path & "
"

If FSO.FolderExists(Path) = false then 'Determine whether the folder exists
FSO.CreateFolder(Path) 'New folder
End If

File = Path & "asptest.txt"
' Write file operation
If FSO.FileExists(File) = True Then 'Judge whether the file exists
' Create TextStream object CTF
Set CTF = FSO.OpenTextFile(File, 8, False, 0) 'Open the file, see the description for details
Else
Set CTF = FSO.CreateTextFile(File, False, False) 'New File
End If
CTF.Write "

First string; " 'Write string
CTF.WriteLine "Second string; " 'Write string, and add A newline character
CTF.Write "The third string; "
CTF.Close 'Be careful to close the file

' Read file operation
Set CTF = FSO.OpenTextFile(File, 1,,0)
Do While CTF.AtEndOfStream <> True 'Determine whether the file ends (loop statement)
Str = CTF.ReadLine '(Every time) Read one line
StrNoHTML = StrNoHTML & Str & "
" & VbCrLf
StrHTML = StrHTML & Server.HTMLEncode(Str) & "
" & VbCrLf
Loop
Response.Write StrNoHTML
Response.Write StrHTML

CTF.Close
Set CTF = Nothing 'Release object
Set FSO = Nothing
%>
CTF = FSO.OpenTextFile(File, 8, False, 0), The first parameter in brackets is the file name; the second parameter is 8, which means appending content after the original file. If it is 1, it means read-only, and if it is 2, the original file will be overwritten; the third parameter, false, means that if the file is specified If it does not exist, the file will not be created. If it is True, it means that the specified file does not exist, and the file will be created; the fourth parameter 0 means opening it in ASCII file format, and if it is -2, it means opening it in the original format.
CTF = FSO.CreateTextFile(File,False, False), the second parameter false means not to overwrite the existing file, if it is True, it means overwrite the existing file; the third parameter False means the file The format is ASCII. True means the file format is Unicode.
The MapPath method of the Server object converts the specified virtual path into a real file path. MapPath treats "/" and "" characters as the same.
The HTMLEncode method of the Server object allows you to HTML encode a specific string, or enable the browser to display specific characters correctly. In the above example, if it is not encoded, "

" will not be displayed, but will be marked as HTML by the browser. You can compare the running results.
In fact, the File Access component is relatively powerful in operating files, folders and drives, and it also provides more methods. If you need to use this knowledge, don’t forget to use it.
In addition, by now, writing a webpage counter is a piece of cake. No wonder so many webpages provide free counters. How about it? Try writing a graphical counter yourself. You can cheat as much as you want. You have the final say. It’s so cool! (A little secret: I have an instance wuf24.asp on my homepage)

3. AD Rotator (advertising flipping component)
When surfing the Internet now, I am afraid that the most annoying thing is the advertising banners on other people’s homepages. My favorite It's an advertising banner on your homepage. Advertising banners are everywhere like spam, making them hard to guard against. You can also create such garbage yourself. ASP's AD Rotator component can randomly display ads every time you open or reload a web page.This example includes three parts:
Routine wuf25.asp
<%@ Language=VBScript %>
<% Option Explicit
Dim adr
'Create AD Rotator object
Set adr = Server.CreateObject("MSWC.AdRotator")
adr.Border = 2 'Specify the border size of the graphic file
adr.Clickable = True 'Indicate whether the displayed image is a hyperlink
adr.TargetFrame = "_blank" 'Whether to specify the Frame name when setting the hyperlink, such as: _TOP _NEW _PARENT
'Get the image and hyperlink settings to be displayed - set
Response.Write adr in the file AdrSet.txt .GetAdvertisement("AdrSet.txt")
%>
AdrSet.txt content (followed by comments, not the content of this file):
REDIRECT wuf26.asp After clicking on the advertisement, transfer to wuf26.asp To handle
WIDTH 468 Advertising Image Width
HEIGHT 60 Advertising Image Height
* Separator
http://www.soyou.com/prog/ad/468x60_1.gif The location of the advertising image, also It can be a local graphic file
http://www.163.com/ pointing to a link. If there is no hyperlink, write a "-"
NetEase text description
20 to display the relative weight of the advertisement, that is Display frequency
http://fp.cache.imgis.com/images/Ad173962St1Sz1Sq1Id2.gif
http://www.sina.com.cn/
Sina
30
http ://61.139.77.73/images/canon.gif You can also use local images, such as ../images/flag.gif
http://www.canon.com.cn/
Canon
50
In this example, there are three pictures (picture size 468X60) and links. The description of each link takes up four lines. In actual use, you can follow the same method and add more pictures.
<% 'wuf26.asp
URL = Request.QueryString("url")
Response.Redirect(URL)
%>
wuf26.asp is the simplest processing program, you can add more code here according to actual needs.
Run it. It turns out that the use of this component is also very simple. All you have to do is get your own AdrSet.txt file. Using this component, you can even design an ad exchange homepage that is now very trendy.

4. Content Linking component
Obviously this component is related to links. If you want to know the specific use of this component right away, I am afraid it is too hasty. You might as well quote a classic example first: Suppose you are reading a book on the Internet Books, you must be familiar with the following links: Chapter 1, Chapter 2,..., previous chapter, next chapter (or previous page, next page), etc. What we have to do now is how to set up jumps between these links easily and quickly.
First create a link list text file, such as urllist.txt
wuf23.asp Chapter 1: File Operation (File Access component)
wuf28.asp Chapter 2: Content Linking component usage example
wuf22.asp Chapter 3: Browser Capability Component
The link URL address and description are separated by the Tab key. The following wuf27.asp is used to list all links in urllist.txt.
<% @LANGUAGE = VBScript %>
<% Option Explicit %>
Content Linking component uses < /head>

Directory list: Note that the core link is Chapter 2, you must click on it



    < %
    Dim NextLink, Count
    'Create Content Linking component
    Set NextLink = Server.CreateObject("MSWC.NextLink")

    'Get the number of links in the file urllist.txt
    Count = NextLink.GetListCount("urllist.txt")

    Dim url, Dscr, I
    For I = 1 To Count
    url = NextLink.GetNthURL ("urllist.txt", I) 'Get hyperlink
    Dscr = NextLink.GetNthDescription ("urllist.txt", I) 'Get text description
    Response.Write "
  • " & Dscr & "" & vbcrlf
    Next
    %>

Then, wuf28 .asp is used as an example to illustrate how to automatically jump to the previous chapter and the next chapter.
<% @LANGUAGE = VBScript %>
<% Option Explicit %>
Pay attention to this link< /head>


Here is the text of Chapter 2......



<% 'Each file contains the following sentence to achieve automatic linking%>


Add the last sentence here to realize automatic jump. The core is in wuf29.asp.
<%
Dim NextLink, rank
Set NextLink = Server.CreateObject ("MSWC.NextLink")
'The current link is located in urllist.txt at which
rank = NextLink.GetListIndex ("urllist.txt")
Response.Write "
"

If (rank > 1) Then 'rank = 1 The previous page
Response does not exist. Write "|Previous Chapter|"
End If

If (rank < NextLink.GetListCount("urllist.txt")) Then 'rank is at the end, there is no next page
Response.Write "|Next Chapter|"
End If
%>
After running this example, you will immediately understand the function of this component, simply In other words, there is no need to write "previous chapter" and "next chapter" on every page. It can be done completely through wuf29.asp. Isn't it very convenient? ! Otherwise, wouldn't it be too troublesome if you modify the link manually?
Now you should understand that there are a large number of free counters, free message boards, free chat rooms, advertising exchange networks, etc. on the Internet. Their principles are just this, so there is no need to worship them.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314730.htmlTechArticleASP built-in components In the first three lectures, we mainly introduced the four built-in objects provided by ASP: lResponse object: to The browser sends the information. lRequest object: Access sent from the browser to the service...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn