ASP programming into the first step (4): Built-in object Request

xiaoxiao2021-03-06  44

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 a platform for input information to submit information to the ASP page below to accept processing)

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%> uses for loop statement, all FORM labels Information is accepted and displayed. This is very fast when there are many items on the table, and come out very quickly. First, it is still Request.form, just behind ("YourName") or ("YourPwd") becomes the variable I traverses the FORM collection via the for loop, which is a different from mechanical "there are several Extract a few "programming ideas, pay attention to master. Second, Request.QueryString ("name") This time is changed by request.form to request.QueryString, what is the method of using the last page form to submit, and what method is employed. 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 Selection Tips: You can modify some code first, then press Run] and TEST1.HTML The biggest difference is Method = "get" 2, Submit2.asp (ASP page, check Name = " YourName "and Name =" YourPwd "two values)

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") where ServerVariables is the server's environment variable, which contains more content, and we will 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 (client machine's environment-related): <% = request.servervariables ( "http_user_agent")%>
http_accept_language (browser language): <% = request.servervariables ( "http_accept_language")%>
CONTENT_LENGTH ( The length of the client issued content): <% = Request.serverVariables ("content_length")%>
Content_Type (content data type. For "text / html". Use the query of additional information, such as HTTP query GET , POST and PUTs: <% = Request.serverVariables ("Content_Type")%>
Local_ADDR (Returns the server address of the received request. If you find the address used by the request to find the request on the multi-hosted master of multiple IP addresses This variable is very important): <% = Request.serverVariables ("local_addr")%>
Remote_addr (IP address of the Request Retriever Client): <% = 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 requests) : <% = 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 it a full URL? 2, Server2.asp

<% a = request.servervariables ("server_name")%> <% b = request.servervariables ("script_name")%> <% = "http: //" & a & b%>

among them

HTTP: //

Caused by quotation marks, it is a string, A and B, respectively, corresponding to specific values, and perform such a connection in the ASP is to use the & number. 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 to the variable filepath and all link addresses begin only The variable is OK. Is it very useful, a bit of a powerful feeling. Fourth, Request.Cookies ("Name") Don't tell me, cookie is a very important thing, how is it, wait until the following object response, there will be special cookie's special lectures. 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 that does not say that an ASP built-in object has an object attribute outside the object collection, and the object of the object method. The object property of the object method is only one is Totalbytes (the number of bytes), you can

<% = Request.TotalBytes%>

This statement is added to the ASP page that accepts data. The object method of the Request object is also one: binaryRead. To be honest, this stuff is not used, I have never used it, huh, huh. OK ~! The study of the Request object is almost the same, the most important is to understand the three object collection, cookies don't worry, continue to learn the object response.

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

New Post(0)