After a long period of accumulation, ASP has a very rich content, but if it is just to develop a simple message book, you only need to master the most basic input and output.
We create a new asp_jichu.asp file, enter "★Basic Input and Output in ASP" in it, and then save it. OK, so we create an ASP file. How about it? It's very simple:) Then we run this ASP file under IIS and we will see the web page "★Basic Input and Output in ASP". Although the content can be displayed, such display has little effect on us. Why is ASP an ASP? This is mainly because it can complete the interaction between the server and the client, such as it can receive variables sent by the client and display the information needed by the client in a specific way based on these variables. The above "asp_jichu.asp" does not have any interaction, so it loses the meaning of ASP.
Before officially starting interactive explanation, it is necessary to talk about the composition of the ASP file first. The composition of an ASP file can be summarized in just one sentence: all ASP statements start with "<%" and end with "%>". Another thing to note is that in IIS, ASP generally uses VBScript by default, but we use javascript, so at the beginning of the ASP file, we need to add a sentence:
<%@LANGUAGE="JAVASCRIPT"%>
To get to the point, first talk about how to pass variables to ASP. There are two methods, namely the common GET and POST methods. The GET method is suitable for passing a small amount of content. Generally within 2K, variables and content will be attached to the URL, variables start with "?", and the variables and content also follow the "variable/value" pairing principle mentioned in the previous article. The POST method can deliver a large amount of content, and the content will not be displayed in the URL. Although the GET method delivers less content and is not safe, it is very intuitive to use for tutorial demonstrations. Now I will use this method to demonstrate how ASP receives variables. Or use the "asp_jichu.asp" file we started to create, enter the following content and save it:
★Basic input and output in ASP<br>
<%@LANGUAGE="JAVASCRIPT"%>
<%
var neirong;
//Get the content of the variable in the URL
neirong=Request("neirong_wangzhi");
//Show variable content
("The content passed from the address bar is: "+neirong);
%>
Then run this file under IIS and we will see the page showing:
★Basic input and output in ASP
The content passed from the address bar is: undefined
First, I need to explain the statement in "asp_jichu.asp". In ASP, the "Request" object is used to receive information, and the "Write" method is used to output the content. It should be noted that when Request receives variables, it needs to be quoted, but when Response outputs variables, it does not. In this way, the above code is not difficult to understand. At the beginning, we define a variable "neirong", and then use it to record the content in the variable "neirong_wangzhi" passed to the ASP, and finally output "neirong". But we did not assign "neirong_wangzhi", so we got "undefined". Now we use the GET method to assign the variable "neirong_wangzhi" to see how it works.
As mentioned earlier, the variables and contents passed by the GET method will be displayed in the browser URL. In fact, this display is an intermediate process. ASP receives variables and processes the final output content based on this intermediate process, that is, the information in the address bar. So we can completely use this intermediate process to directly assign variables in the browser address bar. Open the running "asp_jichu.asp" and add the following content to the URL at the end, press Enter to see what changes are happening in the webpage?
?neirong_wangzhi=I want to make my own FLASH message board
Haha, did you see it? At this time, the web page displays:
★Basic input and output in ASP
The content passed by the browser is: I want to make my own FLASH message board
What does this mean? We received the variable content passed in the address bar, and we succeeded :)
suspect! ? What are you doing there? Why don’t you cheer with me? Do you still don’t understand the GET delivery method? Haha, it doesn’t matter. Through the above demonstration, you only need to remember the following knowledge points:
1. How to form ASP files (all statements are written between "<%" and "%>")
2. How does ASP receive variables passed by the outside world (using a Response object)
3. How does ASP display content in browser (using Response's Write method)
How about it, I don’t have high requirements? As long as you remember the above three points, you should have full confidence to understand the content below me. Come on!
Friendly Tips:
Let's change the content in the "asp_jichu.asp" file into the following form to see if the content displayed on the web page will change?
★Basic input and output in ASP<br>
<%@LANGUAGE="JAVASCRIPT"%>
<%
var neirong;
neirong=Request("neirong_wangzhi");
%>
The content passed by the browser is: <%(neirong)%>
If you change it to the following form, see if there are any changes?
★Basic input and output in ASP<br>
<%@LANGUAGE="JAVASCRIPT"%>
<%
var neirong;
neirong=Request("neirong_wangzhi");
%>
The content passed by the browser is: <%=neirong%>
We will find that the results obtained in the above three forms are the same. It can be seen that the writing of ASP is very flexible. We must grasp its essence and not be confused by various superficial forms:) What needs to be explained here is the last line of code for the last writing method. <%=neirong%> is a short form of output, and its function is equivalent to, only applicable to when the ASP statement has only one line and only outputs a simple variable.
Huhu, it’s OK to know so much about ASP for the time being. The exciting moment is here. We are about to start the interaction between ASP and FLASH!