ASP Getting Started

xiaoxiao2021-04-04  249

Transferred from

http://www.blueidea.com/bbs/newsdetail.asp?id=1375425

System learning ASP is starting with several large built-in objects from ASP. Generally known as five major objects: Request, Response, Server, Session, Application Today, take a look at the Request object. Of course, it has always been mentioned, what is the ASP? How do I know how the code is an ASP code? Very simple, when you see "<%" and "%>" indicate that it is ASP, and between the two is the ASP source code. So why do you want to learn objects, how is the role of an object? In fact, these built-in objects provided by the ASP can be used in the script, which makes it easier for users to collect information sent through the browser, respond to the browser, and the storage user information, so that the object developers get rid of a lot of cumbersome work. The main role of the Request object is to accept and get information submitted or uploaded from the client browser. The REQUEST object can access all information based on HTTP request delivery, including parameters, cookies, etc. from the Form form or get method. 1. Request.form ("name") This is an acceptable way that is often used when accepting information on the previous page. Request is an ASP object, and Form is a collection of objects included in the request object (this is different from the FORM form in the HTML page, which is different), name is a text box in the previous page, password box Or the name of the hidden domain. And it is very important: the submission method of the previous form form must be a POST method. It's better to do it, look at the following two page programs. 1. Test1.html (this page is HTML, mainly providing the input information platform to submit information to the ASP page below)

Your name:

Your PWD:

[Ctrl a All Select Tips: You can modify some code first, then press Run] Note that Method is POST, and the submitted page action is Submit1.asp. 2, Submit1.asp (ASP page, do two values ​​from Test1.html accept Name = "YourName" and Name = "YourPWD")

Your name is: <% = Request.form ("YourName")%>

Your PWD IS: <% = Request.form ("YourPwd")%>

The page debugging of the HTTP protocol via IIS, you will find two pages to associate: Test1.html Name and PWD in the state entered, in Submit1.asp, will also perform the corresponding dynamic display.

This is the whole process of receiving, extracting and displaying information.

3. Improved Submit1.asp

<% for each i in request.form%> <% = i%>:

<% = Request.form (i)%>


<% next%>

With the For loop statement, all FORM tag information on the top page is accepted and displayed. This is very fast when there are many items on the table, and come out very quickly.

First of all, it is still request.form, just behind ("YourName") or ("YourPwd") becomes variable.

i

The FORM collection is traversed by the FOR cycle, which is a programming idea that is different from the mechanical "there are several extraction,", pay attention to master.

Second, Request.QueryString ("Name")

At this time, it is the method of using the request.form to request.QueryString, the most important thing is to use by the last page form. When POST is used, it uses request.form, otherwise it is requested when using a GET. QueryString.

Where is the biggest feature of Request.QueryString? Request.QueryString can retrieve and accept the value of the variable in the HTTP query string, and the HTTP query string is specified by the value (?) Value. Half a half a day, continue to watch a program.

1, TEST2.HTML (this page is HTML, mainly providing input information platform to submit information to the ASP page below), pay attention to the submission method is Get)

Your name:

Your PWD:

[Ctrl A All Select Tips: You can modify some code first, press Run]

And Test1.html The biggest difference is Method = "get"

2, Submit2.asp (ASP page, do two values ​​from Test1.html accept name = "Yourname" and name = "YourPwd")

Your name is: <% = request.queryString ("YourName")%>

Your PWD IS: <% = Request.QueryString ("YourPwd")%>

Note that the browser address bar in this time is over there? number,? The number of variable names and the value being assigned, and of course, multiple variable names are connected to numbers.

And the biggest function of Request.QueryString is possible? The number of variable names later are separated, and the corresponding values ​​are also taken one by one.

Just said that the different variable names are connected to the number, but if it is the same variable name, the request.QueryString is extracted before? last one? Still two?

Use an example to speak. 3, query.asp (name is query.asp, because it is feedback to yourself in this page.)

"ASP tutorial"

" JSP tutorial "

"XSP tutorial"

You chosed <% = request.QueryString ("BookName")%>

It is clear that when the "XSP tutorial" is displayed, "XSP Tutorial", "XML" ", and the middle is automatically added", ".

Finally, it still needs to be explained: request.QueryString is often used in paging programs. Icon http://www.cnbruce.com/database/

Third, Request.ServerVariables ("xxx")

SERVARIABLES is the server's environment variable, which contains more content, and we use the for loop to view.

1, Server1.asp

<% for Each I in Request.ServerVariables%>

<% = i%>:

<% = Request.ServerVariables (i)%>


<% Next%>

You can see a lot of environment variables, which are there in, and there are several more commonly used.

HTTP_USER_AGENT (Related Environment of the Client Machine): <% = Request.ServerVariables ("http_user_agent")%>

HTTP_ACCEPT_LANGUAGE (Browse Language): <% = Request.ServerVariables ("http_accept_language")%>

Content_length (the length of the client issues): <% = Request.serverVariables ("Content_length")%>

Content_type (content of the content. For "text / html". Use the query of additional information, such as HTTP query GET, POST and PUT): <% = Request.ServerVariables ("content_type")%>

Local_addr (Returns the requested server address. If you find the address used on the multi-hook master binding multiple IP addresses, this variable is very important): <% = request.servervariables ("local_addr")%>

Remote_addr (IP address of the Remote Host Client of Remote Host): <% = Request.ServerVariables ("Remote_ADDR")%>

Server_name (server host name, DNS pseudonym, or IP address in the self-reference URL): <% = Request.serverVariables ("server_name")%>
Script_name (virtual address behind the host name): <% = Request .servervariables ("script_name")%>

Logon_user (user logging in to Windows NT): <% = Request.ServerVariables ("logon_user")%>

Server_Port (port number of sending request): <% = Request.serverVariables ("Server_port")%>

According to the above server_name is the extracted server host name, script_name is the extracted virtual address, then the combination of the two plus http: // is a complete URL.

2, Server2.asp

<% a = request.servervariables ("Server_name")%>

<% b = request.servervariables ("script_name")%>

<% = "http: //" & a & b%>

The http: // is caused by quotation marks, indicating that A and B are variables corresponding to specific values, respectively, in ASP, is used to use & numbers.

According to this result, we can extract the dynamic URL address at any time.

Let's take a look at Query.asp, ask you to save as query.asp, because if it is not the file name, the program will make an error.

But now this file is just the same as you save, all of them.

3, XXX.ASP (any file you save)

<% filepath = request.servervariables ("script_name")%>

"ASP Tutorial"

"JSP Tutorial"

"XSP Tutorial"

You chosed <% = request.QueryString ("BookName")%>

First remove the address of the current file and assign the value of the variable FilePath

Then all link addresses will only reference the variable directly to OK.

Is it very useful, a bit of a powerful feeling.

Fourth, Request.Cookies ("Name")

Without me, cookie is a very important thing, how is it, after we learn the following object response, there will be a special cookie's special lecture.

Let's put it first.

The above four uses four objects that are included in the Request object: Form, QueryString, Servervarivables, cookies. Of course, there is a clientCertificate, don't say a ASP built-in object except

Outside the object collection

Object properties,

Object method

Request object

The object property is only one is TotalBytes (the number of bytes), you can

<% = Request.TotalBytes%>

This statement is added to the ASP page that accepts data.

Request object

The object method is also another: binaryread.

To be honest, this stuff is not used, I have never used it, huh, huh.

OK ~! The learning about the Request object is almost the same, the most important thing is to understand the three objects, cookies is not anxious, continue to learn the object in the next step.

转载请注明原文地址:https://www.9cbs.com/read-131727.html

New Post(0)