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

xiaoxiao2021-03-06  47

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:
< /form>2, Submit1.asp (asp page, 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 that two pages have been associated: Test1.html Name and PWD The Submit1.asp also performs a 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%> adopting for loop statement, Accept all the FORM tag information on the previous page and display. 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 the input information platform to submit information to the ASP page below to accept processing, pay attention to the method of submitting the method to run the code box Your name:
Your PWD:
and test1.html The biggest difference is Method = "get" 2, subsmit2.asp (ASP page, check Name = "YourName" and Name = "from Test1.html YourPwd "two values) Your name is: <% = request.QueryString (" YourName ")%>
Your PWD IS: <% = Request.QueryString (" YourPwd ")%> Note this time browser Add the address bar, after the file is 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"

"XSP tutorial"
you chosed <% = request.QueryString (" BookName ")%> When you have a" XSP tutorial ", it 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. I like http://www.cnbruce.com/database/3, request.servervariables ("xxx") where ServerVariables is the environment variable of the server, which contains more content, and we use the for loop to overview . 1, Server1.asp <% for Each I in request.servervariables%> <% = i%>: <% = request.servervariables (i)%>


<% next%> You can see a lot of environment variables There is also no value, 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.

This variable is very important if the address used is found on the multi-hook of multiple IP addresses, this variable is very important): <% = request.servervariables ("local_addr")%>
Remote_addr (Remote Remote Host Client IP Address): <% = Request.serverVariables ("remote_addr")%>
Server_name (appears in the server host name, DNS pseudo name, or IP address): <% = 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 If 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%> where 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 to what file) <% filepath = request.servervariables ("script_name")%> "ASP Tutorial "
" JSP Tutorial "
"XSP Tutorial"
You Chosed <% = Request.QueryString ("BookName")%> First remove the current file's address and assign Variable filepath then all link addresses will only reference the variable directly to OK. Is it very useful, a bit of a powerful feeling.

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

New Post(0)