After reading the article "How to Make Your Website Dynamic", did you feel excited? Are you already eager to build your own dynamic website? This article will focus on Active Server Pages, fully demonstrate the steps and techniques for creating dynamic business websites, and through a large number of examples, you will be proud of the Internet in continuous theory and practice...
The previous chapter briefly introduces some methods and tools for building dynamic websites. This chapter will focus on how to establish an IIS-based ASP dynamic website and reveal the true secrets of dynamic commercial website design step by step. In order to enable you to fully and meticulously master the development skills of ASP, this article will be serialized in the future and teach you how to build your own ASP dynamic website. Since this article was written by the author based on his own learning and practical experience and combined with some foreign language materials, there will inevitably be some bias. I hope you can forgive me. If you find any inappropriate things in this article, please notify the author in time, thank you. Microsoft Active Server Pages, which is what we call ASP, is actually a server-side scripting environment developed by Microsoft. ASP is contained in IIS 3.0 and 4.0. Through ASP, we can combine HTML web pages, ASP instructions and ActiveX components to create dynamics. Interactive and efficient WEB server application. With ASP you don't have to worry about whether the client's browser can run the code you wrote, because all programs will be executed on the server side, including all scripting programs embedded in plain HTML. After the program is executed, the server only returns the execution result to the client browser, which reduces the burden on the client browser and greatly improves the speed of interaction. The following lists some unique features of Active Server Pages:
1. Use simple and easy-to-understand scripting languages such as VBScript and JScript, combined with HTML code to quickly complete the website's application.
2. No compile is required, it is easy to write and can be executed directly on the server side.
3. Use a normal text editor, such as Windows Notepad, to edit and design.
4. Browser Independence is not related to the browser. The user side can browse the web page content designed by Active Server Pages as long as it uses a browser that can execute HTML code. The scripting languages (VBScript and Jscript) used by Active Server Pages are all executed on the WEB server side, and the browser on the user side does not need to be able to execute these scripting languages.
5. Active Server Pages can be compatible with any ActiveX scripting language. In addition to using VBScript or JScript languages, other scripting languages provided by third parties are also used through plug-in, such as REXX, Perl, Tcl, etc. The script engine is a COM (Component Object Model) object that handles script programs.
6. The source program of Active Server Pages will not be transmitted to the client browser, so the source program written can be avoided by others and improve the security of the program.
7. Server-side scripts can be used to generate client-side scripts.
8. Object-oriented.
9. ActiveX Server Components (ActiveX Server Components) have unlimited scalability. You can use Visual Basic, Java, Visual C++, COBOL and other programming languages to write the ActiveX Server Component you need.
There are so many wonders of ASP. Please wear your seat belts below and I will lead you into the dream world of ASP.
First, let's take a look at the environment required to run ASP:
ASP itself is not a scripting language, it just provides an environment where scripting programs embedded in HTML pages can run. However, to learn ASP well, you must master its grammar and rules. Now let's start to understand and learn Active Server Pages step by step.
The ASP program actually exists on the WEB server in plain text with the extension .asp. You can open it with any text editor. The ASP program can contain plain text, HTML tags, and script commands. You can access the ASP program through WWW by simply placing the .asp program in the virtual directory of the WEB server (this directory must have executable permissions). To learn how to design ASP programs well, you must master script writing. So what exactly is script? In fact, scripts are composed of a series of script commands. Just like a general program, scripts can assign a value to a variable, command the WEB server to send a value to the client browser, and define a series of commands into a process. . To write scripts, you must be familiar with at least one scripting language, such as VBScript. Scripting language is a special language between HTML and programming languages such as JAVA, Visual Basic, C++, etc. Although it is closer to the latter, it does not have the complex and rigorous syntax and rules of the programming language. . As mentioned above, the script running environment provided by ASP can support multiple scripting languages, such as: JScript, REXX, PERL, etc., which undoubtedly provides ASP programmers with wide room for play. The emergence of ASP makes WEB designers not have to worry about whether the client browser supports it. In fact, even if you use different scripting languages in the same .asp file, you don't have to worry about it, because everything will be in It is done on the server side, and the client browser only gets the result of the execution of a program, and you only need to declare in .asp to use a different scripting language. Here is a typical example of using two scripting languages in the same .asp file:
<HTML>
< BODY>
< TABLE>
< %Call Callme %>
< /TABLE>
< % Call ViewDate %>
< /BODY>
< /HTML>
< SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Callme
Response.Write < TR>< TD>Call< /TD>< TD>Me< /TD>< /TR>
End Sub
< /SCRIPT>
< SCRIPT LANGUAGE=JScript RUNAT=Server>
function ViewDate()
{
var x
x = new Date()
Response.Write(x.toString())
}
< /SCRIPT>
This is the first real ASP program you have come into contact with in this article. Don't be confused by the < % %> symbol. This is actually a standard ASP delimiter, and the one between < SCRIPT>< /SCRIPT> is Scripting language. ASP is different from a scripting language. It has its own specific syntax. All ASP commands must be included in < % and %>, such as: < % test=English %>, and ASP is included in < % and %> The expression outputs the execution result to the client browser, for example: < % =test %> is to send the value assigned to the variable test English to the client browser. When the value of the variable test is Mathematics, the following program:This weekend we will test < % =test %>.
In the client browser it appears as:
This weekend we will test Mathematics.
The best way to learn ASP is to write it yourself. In order to enable you to master the programming skills of ASP in the shortest time, this article will adopt an example analysis method to let you learn ASP in practice through a series of examples. To create an ASP page, all you need is to open a text editor, such as: Notepad, and then start writing the first ASP program with me. Below we will establish an ASP program that automatically monitors browsing time and dynamically displays different page contents according to different periods. Please clip the following code into your text editor and coexist as test1.asp:
<html>
<body>
< FONT COLOR=Green>
< % If Time < #12:00:00# And Time >= #00:00:00# Then %>
Good morning, the weather is not bad today!
< % ElseIf Time < #19:00:00# And Time >= #12:00:00# Then %>
good afternoon!
< % Else %>
Hello! Have you ever gone to IRC to chat tonight!
< % End If %>
< /body>
< /html>
Save test1.asp in the virtual directory of the WEB server (such as: aspsamp/) and browse it in the browser using HTTP, such as: http://yourcomputername/aspsamp/test1.asp, you will be novel I found that your page really came alive. Although this is just a very simple example, and this function can be completely completed through javascript, it is not difficult to find that using ASP is much simpler and faster than javascript. And using this method, you can easily make your web page Different styles are displayed in different periods. The Time in this example is actually a VBScript built-in function to display the current time of the system. Since the system's default scripting language is VBScript, when you call the function in the ASP command, the script engine will automatically convert it to the current System time. Next we will add a little color to test1.asp, add bgcolor=< % =bgc %> to the <body> tag, that is, it becomes <body bgcolor=< % =bgc %>>, and add it before the <body> tag The following statement:
< % If Time < #12:00:00# And Time >= #00:00:00# Then
bgc=silver
ElseIf Time < #19:00:00# And Time >= #12:00:00# Then
bgc=navy
Else
bgc=red
End If
%>
This way, when users visit your page at different times, they will see different page background colors. There are many things we can do, such as if you want to know the name of the customer who browses your page between the early morning and twelve o'clock and say hello to him or her, then the following program will help you achieve your wish. First you need to set the form in the page and clip the following HTML code to < % If Time < #12:00:00# And Time >= #00:00:00# Then %> After:
Welcome to my homepage, please fill in the following information: <FORM METHOD=POST ACTION=test1.asp>
< P>
First Name: < INPUT NAME=fname SIZE=48>
< P>
Last Name: < INPUT NAME=lname SIZE=48>
< P>
Title: < INPUT NAME=title TYPE=RADIO VALUE=mr>Mr.
< INPUT NAME=title TYPE=RADIO VALUE=ms>Ms.
< P>< INPUT TYPE=SUBMIT>< INPUT TYPE=RESET>
< /FORM>
Then add the following ASP command after the above HTML code: < %
title=request.form(title)
If src="/uploads/allimg/130319/10220915V-0.gif" /> means greetings, then you only need to clip the following command to Good Evening! and then: < % for i=1 to 6 %>
< p>< center>< img src=smile.gif width=32 height=32 alt= Good evening></p>
< % next %>
This is the most basic loop statement, which calls a smiley face image six times and displays it on the page. Of course, the effect of this example can be achieved in HTML, but it is not difficult to find that using ASP greatly shortens the repetitive writing of the code, making the program have good readability. In addition, when you create a review site that rated stars for the subjects you are rated based on user votes, using this method, you don't need to create a picture for each star rating at all. If an object is rated 4 stars, you only need to cycle the image of one star 4 times, and so on. Of course, when the workload is small, you will not feel the benefits of ASP. However, once the data volume increases dramatically, you will deeply experience the unprecedented lightness and refreshing experience that ASP dynamic website brings you!