Lesson Two: Introduction to ASP

Source: Internet
Author: User
Tags current time execution html tags iis object model variable web services client
Read the "How to make your site" dynamic full "of a text, whether to make you exciting? Are you impatient to build your own dynamic Web site? This article will be centered around Active Server Pages to show you the steps and techniques to make a dynamic business site and, through a large number of examples, make you proud of your "network" in constant theory and practice ...

The last chapter gives you a brief introduction to the establishment of dynamic Web site, some of the methods and tools, this chapter will be based on the IIS ASP Dynamic Web site as the center to everyone step-by-step to reveal the real mystery of the design of dynamic commercial websites. In order to enable you to fully and carefully grasp the development of ASP skills, this article will take the form of serialization, hands-on teaching you how to build your own ASP Dynamic Web site. Because this article is the author according to own study and the practical experience and unifies some foreign language material to write, therefore unavoidably may have some biased, hoped that everybody forgive me.    If you find any improper in this article, please notify the author in time, thank you. Microsoft Active Server Pages, what we call ASP, is actually a set of Microsoft-developed server-side scripting environments, which are embedded in IIS 3.0 and 4.0, with ASP we can combine HTML pages, ASP directives, and Ac Tivex components to create dynamic, interactive, and efficient WEB server applications. With ASP you don't have to worry about whether the client's browser will be able to run the code you write, because all programs will be executed on the server side, including all the scripting programs 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 increases the speed of the interaction. Here's a list of some of the features unique to Active Server Pages:
1. Using simple scripting languages such as VBScript, JScript, and HTML code, you can quickly complete your Web site's applications.
2. No compile compile, easy to write, can be directly implemented on the server side.
3. Use a normal text editor, such as a notepad for Windows, for editing and design.
4. Browser-Independent (Browser independence), the client can browse the content of Web pages that are designed by Active Server pages as long as they use an executable HTML code browser. The scripting language (VBScript, Jscript) used by Active server Pages is executed 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 JScript languages, other scripting languages provided by third parties, such as REXX, Perl, TCL, are used in plug-in. The scripting engine is a COM (Component object Model) object that handles a script program.
6.Active Server Pages of the source program, will not be uploaded to the client browser, so you can avoid the written source program by others plagiarism, but also improve the security of the program.
7. Server-side scripts can be used to generate client script.
8. Object Oriented (object-oriented).
9.ActiveX Server components (ActiveX server component) has unlimited scalability. You can use the programming languages of Visual Basic, Java, Visual C + +, COBOL to write the ActiveX Server Component you need.

The wonders of the ASP are countless, below please fasten your seatbelt, I will lead you into the dream world of ASP.

first, let's look at the environments that are 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 in the preceding article, unlike general procedures,. ASP programs do not need to compile, the control of the ASP program is used in VBScript, JScript and other scripting languages to design, when the implementation of ASP program, the script will send a complete set of commands to the script interpreter (i.e. script engine), explained by the script Translator and converts it to a command that the server can execute. Of course, as with other programming languages, ASP program writing also follow certain rules, if you want to use your favorite scripting language to write ASP program, then your server must have the ability to interpret this scripting language 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 system default scripting language according to your preferences, about how to change the system default scripting language See theusing scripting languages in ASP"article.

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

The ASP program actually exists on the WEB server in plain text format with the extension. asp, you can open it with any text editor, and the ASP program can contain plain text, HTML tags, and script commands. You simply place the. asp program in the WEB server's virtual directory (the directory must have executable permissions), you can access the ASP program via WWW. To learn the design of ASP program, must master the script writing, then what is the script? In fact, the script is composed of a series of script commands, like a normal program, the script can assign a value to a variable, you can command the WEB server to send a value to the client browser, you can also define a series of commands as a process. To write a script, you have to be familiar with at least one scripting language, such as VBScript. A scripting language is a special language between HTML and programming languages such as JAVA, Visual Basic, and C + +, and although it is closer to the latter, it does not have complex, rigorous syntax and rules for programming languages. The scripting environments provided by ASP, as described earlier, can support multiple scripting languages, such as JScript, REXX, PERL, and so on, which undoubtedly provide an extensive scope for ASP programmers. The advent of ASP has made it unnecessary for the vast majority of WEB designers to worry about whether or not to support customer browsers in fact, even if you're using 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 result of a program execution, And you just have to declare in. asp that you can use 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 your first contact in this article of the real ASP program, do not be "<%%>" symbol confused, this is actually the standard ASP delimiter, and "< script></script>" between the scripting language. Unlike the scripting language, ASP has its own specific syntax, and all ASP commands must be contained within <% and%>, such as <% test= "中文版"%>, ASP through the expressions included in <% and%> Row results to the customer browser, such as: <% =test%> is to send the value of the previously assigned to the variable test in the customer browser, and when the value of the variable test is mathematics, the following program:
This weekend we'll test <% =test%>.

In the client browser, it appears as:
This weekend we'll test mathematics.

The best way to learn ASP is to write in person, in order to enable you in the shortest possible time to master the design skills of ASP, this article will take the example analysis, through a series of examples to let you learn in practice ASP. To create 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 establish an automatic monitoring browsing time and dynamically display different page content according to different period of ASP program, please clip the following code into your text editor, coexist for 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! Did you have a chat on IRC tonight?
<% end If%>
</body>

Save Test1.asp to the WEB server's virtual directory (such as: aspsamp/) and browse in the browser using HTTP, such as: http://yourcomputername/aspsamp/test1.asp, you will find novelty, Your page is really alive. Although this is a very simple example, and this functionality can be done through JavaScript, it is easy to find that using ASP is much simpler and faster than JavaScript, and by using this method, you can easily make your pages show different styles at different times. In this case, "time" is actually a function in VBScript that displays the system's current time, because the default scripting language of the system 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 bit of color to test1.asp, add "bgcolor=" <% =BGC%> to the < body> logo "that becomes < body bgcolor=" <% =BGC%> "> , and 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
%>

 

As a result, when users visit your pages at different times, they will see different background colors for the page. There are many things we can do, such as you want to know the name of the customer browsing your page between midnight and 12, and say hello to him or her, and the following procedure will help you achieve your wish. First you need to set up the form in the page, the following

H

TML

Generation

Code clip to "<% If Time < #12:00:00# and Time >= #00:00:00# Then%>":

Welcome to my homepage, please fill in the following information: < FORM method= "POST" action= "test1.asp" >
< p>
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 HTML code above: <%
Title=request.form ("title")
If title= "Mr" then
%>
You are welcome to mr.<% =request.form ("fname")%>.
<% ElseIf title= "MS" then%>
You are welcome to ms.<% =request.form ("fname")%>.
<% Else%>
< b>< font color=blue> welcome you <% =request.form ("fname") & "" &request.form ("lname")%>. </font></b>
<% End If%>

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

This is actually a common feature on the Internet and on the intranet, when users fill out a form on the browser side, and then send the user data to the server by calling a common Gateway program, which is processed by the server and then returned to the client browser. In the past, it was necessary to write a CGI program that was independent of HTML in order to implement such a function, and the use of HTML to invoke, aside from the CGI complex and other shortcomings do not talk about the efficiency of CGI is also a big problem, each form (form) must execute an executable document, when more than one person on-line use, The simultaneous execution of multiple documents will significantly reduce the speed at which the WEB server executes, and today the ASP provides a completely integrated programming environment that is obviously much easier to use than CGI.

At the end of this issue, let's look at the cyclical functionality of the ASP, for example, if you want to show 6 smiley faces in the middle of the page when the customer browses your page from 7:00 to 0:00:00, you only need to clip the following command to the good evening! "later: <% for I=1 to 6%>
< p>< center>< img src= "http://edu.cnzz.cn/NewsInfo/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 is displayed on the page. Of course, the effect of this example can be done with HTML, but it is not difficult to find that the use of ASP greatly shorten the code of repeated writing, so that the program has good readability. In addition, when you make a rating site that evaluates a star based on a user's vote, you don't have to make a picture for each star at all. If an object is rated as 4 stars, then you just need to loop the picture of one star 4 times, and so on. Of course, when the amount of work is small, you will not feel the benefits of ASP, but once the volume of data increase, you will be deeply aware of the ASP dynamic site to bring you unprecedented light, cool feeling!



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.