ASP Basics Tutorial: Introduction to ASP

Source: Internet
Author: User

See how to make your site "dynamic" article, whether to make you feel excited? Are you impatient to build your own dynamic website? This article will focus on Active Server Pages and give you a full demonstration of the steps and techniques for making a dynamic commercial website, and through a number of examples, Let you in the continuous theory and practice to be proud of "network" ...

The previous chapter gives you a brief introduction to the establishment of dynamic Web site of some methods and production tools, this chapter will be based on how to set up an ASP Dynamic Web site for IIS as the center to everyone step-by-step to reveal the real mystery of dynamic commercial website design. In order to enable you to fully and carefully grasp the development skills of ASP, this article will take the form of serial, hand in hand to teach you how to build your own ASP dynamic website. As this article is based on their own learning and practical experience and combined with a number of foreign language materials written, so there will inevitably be some biased, I hope you forgive me. If you find anything inappropriate in this article, please inform the author in time, thank you.

Microsoft Active Server Pages, what we call ASP, is a set of Microsoft-developed server-side scripting environments that are embedded in IIS 3.0 and 4.0, and we can combine HTML Web pages, ASP directives, and Ac with ASP Tivex components Create dynamic, interactive, and efficient WEB server applications. With ASP, you don't have to worry about whether the client's browser can run the code you write, because all of the programs are executed on the server side, including all the scripts that are embedded in normal HTML. When the program is finished, the server only returns the results of the execution to the client browser, which reduces the burden on the client browser and greatly improves the speed of the interaction. The following lists some of the features that are unique to Active Server Pages:

1. Use simple scripting languages such as VBScript, JScript, and HTML code to quickly complete the application of your website.

2. No compile compilation, easy to write, can be directly executed on the server side.

3. Use a normal text editor, such as Notepad in Windows, to edit the design.

4. Browser-Independent (Browser independence), users can browse the Web page content that is designed by Active Server pages as long as they are using an executable HTML-code browser. The scripting language used by Active server Pages (VBScript, Jscript) is performed on the WEB server side, and the client's browser 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 being designed using VBScript or the JScript language, other scripting languages provided by third parties, such as REXX, Perl, TCL, and so on, are used in a plug-in manner. The scripting engine is a COM (Component object Model) object that handles scripting.

6.Active Server Pages source program, will not be uploaded to the client browser, thus can avoid the writing of the source program was stolen by others, but also improve the security of the program.

7. The client script can be generated using server-side scripts.

8. Object Orientation (object-oriented).

The 9.ActiveX server components (ActiveX server component) has unlimited scalability. You can use the visual Basic, Java, Visual C + +, COBOL, and other programming languages to write the ActiveX Server Component you need.

The magic of ASP is so numerous, please fasten your seat belts below, I will lead you into the dream world of ASP.

First, let's look at the environment required to run ASP:

* Microsoft Internet Information Server version 3.0/4.0 on Windows NT server

* Microsoft Peer Web Services Version 3.0 on Windows NT Workstation

* Microsoft Personal Web Server on Windows 95/98

As mentioned earlier, unlike the general procedure, the. ASP program does not need to compile, the control part of the ASP program is designed using scripting languages such as VBScript, JScript, and when the ASP program is executed, the script sends a set of commands to the script interpreter (that is, the scripting engine), which is interpreted by the script Translator and convert it to a command that the server can execute. Of course, like other programming languages, the ASP program is written in accordance with certain rules, if you want to use your favorite scripting language to write ASP programs, then your server must have to explain the scripting language of the script interpreter. When you install ASP, the system provides two scripting languages: Vbsrcipt and JScript, while VBscript is the default scripting language for the system. You can also change the default scripting language according to your preferences, and see the article "Using scripting language in ASP" for how to change the default scripting language of the system.

The ASP itself is not a scripting language, it simply provides an environment in which script programs that are embedded in HTML pages run. However, to learn the ASP and must master its grammar and rules. Now let's start by knowing and learning about Active Server Pages Step-to-step.

The ASP program actually exists on the WEB server in plain text with the extension. asp, and you can open it with any text editor, which can contain plain text, HTML tags, and script commands. You simply put the. asp program in the WEB server's virtual directory (the directory must have executable permissions), you can access the ASP program by WWW. To learn the design of ASP program, you must master the script, then what is the script? In fact, the script is composed of a series of script commands, like a general program, the script can assign a value to a variable, you can command the WEB server to send a value to the customer browser, You can also define a sequence of commands as a procedure. To write a script, you have to 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 + +, although it is closer to the latter, it does not have the complex, rigorous syntax and rules of the programming language. As mentioned earlier, the scripting environment provided by ASP can support a variety of scripting languages, such as: JScript, REXX, PERL and so on, which undoubtedly gives the ASP programmer a wide range of play. The advent of ASP makes it unnecessary for WEB designers to worry about whether or not to support the customer's browser, in fact, even if you use a different scripting language in the same. asp file, you don't have to worry about it because everything is going to be done on the server side, and the client browser gets just the results of a program execution. And you just have to declare it in. asp with a different scripting language. The following is a typical example of using two scripting languages in the same. asp file:

< html>

< body>

< table>

<% call Callme%>

</table>

<% call Viewdate%>

</body>

< 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 contact in this article, do not be confused by the "<%%>" symbol, which is actually the standard ASP delimiter, and "< script></script>" between the scripting language. ASP is different from the scripting language, it has its own specific syntax, all ASP commands must be included in < and%>, such as: <% test= "English"%> the ASP will execute the result by an expression contained in <% and%> Output to the customer's browser, such as: <% =test%> is the value of the previous assignment to the variable test English sent to the customer browser, and when the value of the variable test is mathematics, the following program:

This weekend we'll test <% =test%>.

In the customer browser, it appears as:

This weekend we'll test mathematics.

The best way to learn ASP is to hand-write, in order to get you in the shortest possible time to master the ASP programming skills, this article will take an example analysis, through a series of examples to let you learn ASP in practice. To build an ASP page, all you need to do is open a text editor, such as: Notepad, and then start writing the first ASP program with me. Below we will create an ASP program that automatically monitors the browsing time and dynamically displays the content of different pages according to different times, and then clip the following code into your text editor, 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%>

Ah, Hello! Did you go to IRC to chat tonight?

<% End If%>

</body>

Save the test1.asp in the WEB server's virtual directory (for example: aspsamp/) and browse in the browser using HTTP, such as: http://yourcomputername/aspsamp/test1.asp, you will find it in novelty, Your page really is alive. While this is a very simple example, and it can be done entirely by JavaScript, it's not hard to see that using ASP is much simpler and faster than JavaScript, and using this method, you can easily make your pages show different styles at different times. The "time" in this example is actually a function of VBScript's built-in display of the current times of the system, since the system default scripting language is VBScript, so when you call the function in an ASP command, the script engine automatically converts it to the current system time. Next we will add a little color to test1.asp, add "bgcolor=" <% =BGC%> "to < body bgcolor=" <% =BGC%> "in the < Body> logo, and in < add the following statement before the body> tag:

<% 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 a different page background color. There are a lot of things we can do, for example, if you want to know the name of the customer who is browsing your page between midnight and 12, and say hello to him or her, then the following procedure will help you to achieve your wish. First you need to set up the form on the page, and then 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= "" ">

< p>

Last Name: < INPUT name= "lname" size= "" ">

< 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 title= "Mr" then

%>

Welcome to your Mr.

<% ElseIf title= "MS" then%>

You are welcome to ms.<% =request.form ("fname")%>.

<% Else%>

< b>< font Color=blue> welcomes you <% =request.form ("fname") & "&request.form (" lname ")%>. </font></b>

<% End If%>

Save the file test1.asp and browse in the browser in HTTP mode, if the system time is between 0:00:00 and 12:00:00 noon, the browser will display the following screen:

  

This is a common feature on the Internet and Intranet, that is, when the user finishes filling out the form on the browser side, the user data is transferred to the server by invoking a common gateway program, which is processed by the server before returning the result to the customer's browser. In the past, in order to achieve such a function must write a separate from the HTML of the CGI program, and through the HTML call, aside from the shortcomings of CGI writing complex, CGI execution efficiency is also a big problem, each form (form) should execute an executable document, when more than one person online use, Multiple documents are executed at the same time, which greatly reduces the execution speed of the WEB server, and today ASP provides a fully integrated programming environment with HTML, which is obviously much more convenient than using CGI.

At the end of this issue let's take a look at the ASP loop function, for example, you want to show 6 smiley faces in the center of the page when the customer browses your page from 7:00 to 0:00:00 in the evening

  

Say hello, then you just need to paste the following command into the "good evening! "Back: <% for I=1 to 6%>

< p>< center>< img src= "smile.gif" width= "+" height= "+" alt= "Good Evening" ></p>

<% next%>

This is the most basic loop statement that repeats a smiley face image six times and appears on the page. Of course, the effect of this example can be done in HTML, but it is not difficult to find the use of ASP greatly shortened the code of repeated writing, making the program has good readability. In addition, when you make a site that evaluates ratings based on a user's vote, using this method, you don't have to make a picture of each star at all. If an object is rated as 4 stars, simply cycle the picture of a star 4 times, and so on. Of course, when the workload is small, you do not feel the benefits of ASP, however, once the volume of data greatly increased, you will be deeply aware of the ASP dynamic website to bring you unprecedented light, cool feeling!

ASP Basics Tutorial: Introduction to ASP

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.