ASP Lecture One: Web Development Tool: Efficient and Easy-to-Learn ASP
Author:Eve Cole
Update Time:2009-05-30 19:58:24
Web development tool: efficient and easy-to-learn ASP
Don't be surprised, I chose such a nondescript name instead of "ASP Beginner (entry, basic)" for two reasons: First, I am afraid that it will be too cliché, but more importantly, I am afraid that there will be many people who are wandering outside the threshold of ASP. The homepage production team ran away without even meeting the content. It’s a pity! In fact, as long as you have experience in making web pages, you should know how to use ASP. Otherwise, your homepage may not be "cool" enough. How to say this? If you have been writing .htm or .html files when making your homepage, you will definitely be surprised. How to display the IP address and the number of people online on the homepage? How to prevent the client from obtaining the source code of its own home page file? Or how to implement personalized services that are very fashionable nowadays (automatically generate pages according to the different requirements of viewers), or how to make counters, guestbooks, automatic links or even electronic shopping by yourself? Then, after reading this lecture, you will probably feel that the implementation principles of these things are so simple. In this case, let’s continue reading.
1. First, let us understand the basic requirements for learning ASP.
1. The minimum personal configuration required to get started with ASP:
(1) Understand a little knowledge of HTML (have experience in maintaining and creating web pages);
(2) A little database knowledge, such as being able to use Microsoft Access or using .mdb database.
(3) It is best to have a little bit of programming foundation (preferably VB series, and it is required to use If...Then...End If to select branch statements and loop statements). If you have no programming foundation at all, you can only give it a try.
2. The software environment required to debug and run ASP:
(1) Win9x+PWS (just install "add-onspwssetup.exe" in the Win98 CD). As for how to install Personal Web Server, it has been introduced in many magazines (not too many, Computer Business Intelligence published an "ASP Personal Getting Started Guide" last year). It is actually very simple and not as complicated as the article said. If you can't pass this test, I have no choice but to suggest you call the editorial department for consultation.
(2) Or use Windows NT4.0+IIS4.0 (in the Windows NT4.0 Option Pack installation program). If you want to build an intranet in the unit, it is better to use this combination.
After the installation is completed, if the result comes out when entering http://localhost/default.asp in the browser, the installation is successful (by default, your homepage file should be placed in the "InetPubwwwroot" directory). If you want to upload the debugged ASP file to a remote homepage server, you must make sure that the server supports ASP. However, there are currently not many free homepage spaces that state that they support ASP. Here are two for you: Dongguan Window (http: //www.homecn.com/) and NET668 (http://freenet.net668.net/), you can test the running results of my ASP file: http://202.103.176.81/grun/kissher/asp/ipfound2 .asp.
3. ASP learning support:
(1) ASP technology website: http://www.chinasp.com/, where you can also find some ASP-related English sites.
(2) ASP dynamic network: http://active.t500.net/
(3) Windows NT4.0 Option Pack documentation and Active Server Pages3.0 documentation.
(4) There are two files in the MSDN Library CD of Visual Studio 6.0, asp.chm and aspdoc.chm, which are ASP help files. If they are not available, you can download them from my website http://wuf.bentium.net (you can also download all the files in this article) source program).
(5) The purpose of this lecture is only to teach you how to use ASP in your own homepage (including directly using the downloadable ASP program), with practicality first. If you want to go further, it is recommended to buy an ASP manual, such as: "ASP Practical Classics" (China Railway Publishing House, edited by Lin Jinlin).
2. Try it yourself. In order to enhance perceptual understanding, we first illustrate how to edit and use ASP files through two examples. Open the Notepad of the Windows attachment, enter the following code, and save it as wuf1.asp (if you have any questions, you can go to my homepage to consult me):
<% @LANGUAGE = VBScript %>
<%
Response.Write "<HTML><BODY>" 'Equivalent to the output statement in a programming language
Response.Write "Output the results to the browser."
Response.Write "</BODY></HTML>"
%>
After editing, place wuf1.asp in the home directory "InetPubwwwroot" where the default Web site is installed, and enter http://localhost/wuf1.asp in the browser to see the output. Let’s look at another example (wuf2.asp):
<html>
<body>
IP address = <%=Request.ServerVariables("Remote_Addr")%>
</body>
</html>
The output result is the local IP address, simple. In the above two examples, we use Notepad as the editor (because ASP files are text files). However, if you really want to use ASP, I recommend the following tools to you:
1. HomeSite: Not only is it one of the best tools for making homepages, it is also great for writing ASP files.
2. ASP-Edit Professional: not only can display ASP codes in different colors, but also has ASP courses and VBScript help. These two files can be downloaded from the Huajun homepage (http://www.newhua.com).
3. Microsoft Visual InterDev6.0: Although it is a powerful tool, it is the best tool for editing ASP files. If you have used VB, I don’t need to say more about its benefits.
It should be noted that the popular DreamWeaver 3.0 is good for making homepages, but it is best not to use it to edit files with ASP code, so as not to make the editing more messy.
3. Understand the ASP script programming environment
ASP (Active Server Pages) is a powerful, flexible and easy-to-learn server-side scripting environment. Its source code is run on the server side, and the running results are output to the client in the form of HTML code. Using ASP, you can not only quickly create interactive dynamic web pages, but also keep the program code completely confidential. More importantly, you don't need to consider which browser the client user uses, and it can be applied to various browsers. If you use client-side scripting (such as VBScript or JavaScript), you must consider the browser used by the user. We can understand the ASP program like this:
1. As can be seen from the above two examples, the extension of ASP file is .asp. An ASP file usually consists of ASP script commands, HTML tags and text. ASP commands must be enclosed in "<% %>" (about <% @LANGUAGE = VBScript %>, don’t rush to figure it out now, we’ll talk about it later).
2. To understand the ASP program, beginners only need to divide it into two parts (do not mix them together to make them confused). Note that after removing the code enclosed by <% %>, it will be the same as the .htm file you have used, and you can understand it at a glance. After the part enclosed by <% %> is run on the server side, the output result is the HTML code you are familiar with. For example, Response.Write "<HTML><BODY>" will get <HTML><BODY>, and the running result of <%=Request.ServerVariables("Remote_Addr")%> will be the IP address, as shown in the output of wuf2.asp It actually looks like this:
<html>
<body>
IP address = 16.62.5.60
</body>
</html>
You can deepen your understanding by selecting "Source File" under the "View" menu in IE.
4. Sharpen the knife and chop wood without missing a beat - ASP basics
1. Output the result (string information) to the browser, the syntax is: Response.Write the displayed content. As can be seen from the example wuf2.asp, you can use "<%=displayed content%>" to replace "<%Response.write displayed content%>".
2. Using variables, wuf2.asp can be changed to:
<% @LANGUAGE = VBScript %>
<% 'Add comment after single quote – wuf3.asp
Option Explicit 'requires variable declaration, using it can reduce the possibility of program errors and improve efficiency
Dim IPaddr 'It is best to declare variables before using them
Ipaddr = Request.ServerVariables("Remote_Addr")
%>
<html>
<body>
IP address = <%=IPaddr%>
</body>
</html>
3. Use functions in your program:
<%@ Language=VBScript %>
<%Response.Expires = 0%>
<HTML>
<HEAD>
<title>Use function - wuf4.asp</title>
</HEAD>
<BODY>
<P>Today’s date: <% = Date%></P>
<P>Current time: <% = Time%></P>
<P>Current time: <font color="#CC0033"><% = Time%></font></P>
<%Response.Write "<P>The current time: <font color='#CC0033'>" & Time & "</font></P>"%>
</BODY>
</HTML>
In the above example, "&" is equivalent to the "+" sign, and Date and Time are functions (note: the time obtained here is the time of the Web server, not the time of the machine where the browser is located. From here, it can be verified that the ASP command is in (executed on the server side), ASP has many other functions, it is impossible to list them all in this article, please check them out yourself.
As for <%Response.Expires = 0%>, we know that browsers can cache Web pages to speed up access, and Response.Expires is used to set the time (minutes) that web pages remain in the client browser cache. If set to 0, it indicates that the web page data will not be retained in the client's cache. It must be placed before the <HTML> tag. Specifically in this example, if there is no such setting, the time will be updated only if you press the "Refresh" button, and the time will not change if you just press Enter in the address bar. With this setting, the time will not change every time you press Enter. Once you press Enter, the time will be updated.
4. Use conditional statements:
<%@ Language=VBScript %>
<% 'wuf5.asp
If Time<=#12:00:00# Then
Response.Redirect "wuf1.asp"
ElseIf time<=#18:00:00# Then
Response.Redirect "wuf2.asp"
Else
Response.Redirect "wuf3.asp"
End If
%>
The date is enclosed in ##. Response.Redirect is responsible for guiding the client browser to display a new web page, which is commonly referred to as redirection. Please remember that this function is very useful.
5. Use loop statements:
<%@ Language=VBScript %>
<%Option Explicit%>
<HTML>
<BODY>
<%
dim I
While I<=5
Response.Write "<P>" & "There are other loop structures, such as: Do...Loop While, " &_
"Do While...Loop, For...Next,For Each...Next, etc." & "</P>"
I=I+1
Wend
%>
</BODY>
</HTML>
From the above example, you should pay attention to how to use "_" for line breaks.
6. Use include files. For a Web site, generally the top or bottom of each page is basically the same, so you can put these same parts in a file and then reference it when needed. First edit a file named comm.asp as follows:
<html>
<head>
<style type="text/css">
<!--
font { font-family: "宋体", "Times New Roman"; font-size: 9pt}
-->
</style>
</head>
<body>
<table width="640" border="0" bordercolor="#9999FF" bgcolor="#FFFFFF" bordercolorlight="#3333FF" bordercolordark="#CC0000">
<tr bgcolor="#006666" bordercolor="#009933">
<td align="center" height="18" colspan="2"><font color="#FFFFFF">⊙
Copyright of "Fengzi Homeland" - </font><font color="#FFFF00">The website was established in March 1997</font>
</td> </tr>
</table>
</body>
</html>
Then edit the following files:
<% @LANGUAGE = VBScript %>
<HTML>
<BODY>
<% 'wuf7.asp
Response.Write "Output the results to the browser."
%>
<!--#include file="comm.asp"-->
</BODY>
</HTML>
The include file can be placed anywhere on the web page, but it must be outside all ASP code blocks.
In addition, there are concepts such as procedures, functions, parameter transfers, etc. If you have not been exposed to it before, it is better to leave it alone and understand ASP in general, and then gradually refine it.