The language characteristics of ASP (Active Server Page)

zhaozj2021-02-11  257

The language feature of ASP (Active Server Page "comes from static text, and now many sites are almost use in this way. The disadvantage of static text is that it is difficult to maintain (the number of files), the query is difficult, and the modification is difficult. Although FrontPage can be used to manage the site, this is just one of the methods. Now, many sites will use the database in the background, dynamically generate hypersitations. In this way, to change the model, simply modify several files; to change the content, simply operate the database, and easy to maintain the system; for full-text search and other query applications, this method is more prominent. (Frequent "dynamic" also includes dynamic display of pictures, such as dynamic gif, java applet, etc., this article refers to Dynamicity Dynamicity) Universal Gateway Interface CGI (Common Gateway Interface) and Network Server Applications ISAPI (Internet Server Application programming interface The emergence of other related technologies allows us to easily communicate with Web Server, so that the CGI program such as some counters, the message is successively treated. But these CGI programs have a big shortcoming, that is, CGI (available for VB, Java, Perl, C or DEPHI et al.) And HTML can only be written separately, run separately, it is not easy to combine both. It is quite difficult to lead to maintenance and writing. Therefore, some vendors have later launched their own script language to enhance the functionality of web development. Where Netscape launches JavaScript (two types of For Client and For Server); Microsoft introduces two types of VBScript and ASP (Syntax's syntax of ASP), which is also used for server-side and client programs. For professional developers, the most important point of the client program is versatility, and the server-side emphasizes functionality and efficiency. For the development of Client-end programs, JavaScript is undoubtedly best, because both mainstream browser IE and Netscape today claim to support this standard; VBScript only IE can support. But what makes us distracted is that some of the JavaScript tags, some versions of IE or IE will not be supported, which must cause us to move some of the program to the server, because the server's program will explain the generation HTML (or ActiveX) text, then send it to the client, there is no compatibility problem. Likewire (JavaScript For Server End Compile), like ASP, is a manuscript language (manuscript means JavaScript similar to the Client), which can be nested inside the HTML text, just mark the program segment executed by the server) It is also the same object-oriented language like C / C . LiveWire's file hyperfix name or HTML, ASP's file subrush name is ASP, because the ASP file is interpreted when the client reads it, and the LiveWire's file must be pre-compiled (after each revision, To recompile it. ASP has a corresponding auxiliary development tool (INTERDEV) that can produce some controls. Of course, these are not important. The key is that you use Netscape Web Server or Microsoft IIS. But in general, because IIS is bundled in NT, users use IIS to be more. Since Netscape launched LiveWire and Microsoft launched an Active Server Page, the programmer was easy to write online programs and easily. But this Script class language has a common disadvantage, that is, because it is explained, the speed will not be too fast.

Recently, Microsoft recommends using a three-layer model. The intermediate layer can be used without ASP, and directly using the ActiveX control generated by VB6.0, because it is compiled, the speed is faster, but this is later. 1. ASP's basic object ASP (Active Server Page) is an object-oriented programming similar to VB. Here, there is no need to detail some basic concepts such as objects, but directly introduce its language characteristics so that developers can be able to modify and prepare the ASP program (because many people just use development tools such as Interdev to generate ASP programs) . First, the archive name of the ASP program is definitely "ASP"; secondly, in the ASP program, the Script of the server is in the middle of the <% and%> string, such as <% user = request ("user")%>. If you want to call another ASP file in an ASP file, you can add the following declaration in the ASP: , this is like C #Include in the language. Where Virtual represents the virtual file path, File represents a real file path. ASP has five main built-in objects: Request, Response, Server, Session, Application, which will be described below. 1.1 Request ASP still complies with the popular, using the client's Form to perform data exchange. The ASP built-in Request object has five methods for obtaining client data (QueryString / Form / Cookies / ServerVariables / ClientCertificate). Syntax: Request. Method Name ("Parameters) | Request (" Parameters) If the latter is adopted, the system will automatically select the appropriate method. 1.1.1 Form re-emphasizes some properties of FORM:

Using FORM transmission information generally three ways: Form biochemistry within the HTML web page to other ASP; other ASP information to another one The information within the ASP is delivered to itself. Syntax: request.form (parameter)] The parameter represents the name of the element in the Form, the index indicates the sequence number of the same name element. Example: <% for i = 1 to request.form ("user"). Count response.write request.form ("user") (i) Next%> Cyclic to read the element name User, where count is Form The system properties are used to calculate the number of the same name element. If the element does not exist, its value is zero. If you do not specify whether to read the same name element, you will read all the values ​​of all the same name elements, and use ",".

Example: Request.form ("User") = ABC, BCD, CDE 1.1.2 QueryString Syntax: Request.QueryString (parameter) [(Index)] In addition to the FORM transfer data, can it be followed by the hyperlink "? "The way information is transmitted, such as: , then read the transfer information via request.QueryString (" User "; if multiple renewed Parameters, such as: , the first time RESQUEST.QUERYSTRING ("User") = ABC, the second RESQUERYSTRING ("User" ) = BCD, the third RESQUEST.QUERYSTRING ("User") = CDE. 1.1.3 ServerVariables Syntax: ServerVariables (parameter name) We know that Web / Browse's transfer protocol is HTTP, HTTP's headers have some client information, such as customer IP addresses, browser language systems, etc. At this point, you can get relevant information through request.servervariables ("***"), such as Request.ServerVariables ("Accept_Language" to get the language of the client browser. Other system parameters are shown in the following table: Server_name Server machine name or IP address. Server_Port Server is running port numbers. Request_method issued a method of request (Get / Post / Head). The path of the script_name program is called, such as CGI-BIN / A.PL. Remote_host issues the name of the remote machine (Client) of the Request request. Remote_addr issues the IP address of the remote machine (client) of the Request request. Remote_ident issues the user name (if the dial-up net, for the user ID), when the NCSA IdentityCheck is Enabled, and the Client machine supports RFC 931, the variable is valid. The MIME type of Content_Type data, such as "text / html". HTTP_ACCEPT Client Acceptable MIME Type List. HTTP_USER_AGENT Client issues a Request's browser type. HTTP_REFERER The text URL referred to before reading the CGI program. 1.1.4 Cookies In the client, cookies record a lot of information on the client browser, and we can get its values ​​via the Request.Cookies command, or via response.cookies ("name") = value "Record some information on the client to control the visitor. Setup multiple cookies to response.cookies ("name") ("name") = "value".

1.1.5 Cache We can set the information that extracted the accessed pages from Cache on the browser, similarly to similar settings in the ASP program. Among them, Response.clear is the memory of the empty client. Response.buffer = true settings can be read from the Cache (default is false). 1.1.6 ClientCertificate ClientCertificate is used to obtain the identity confirmation information of the client browser (in accordance with the X.509 standard), but the client browser must support the SSL3.0 or PCT1 protocol. Here you need to do two steps, the first step: Web Server must start the User-end authentication option; step 2: The client browser is set according to, so that this method will take effect, otherwise, return the EMPTY value. 1.2 Response When you want to transfer information from the server to the client, you can directly output information by following the following methods: 1) Response.write "". 2) Response.Redirect Boot the client to another URL location, such as response.Redirect "http://zyr.yeah.net", but there is a question to pay attention to this statement must be placed before tag Implementation, that is, it is necessary to execute before the server is sent to the client, otherwise the transmission error message will occur. 3) Response.contentType Control The file type of the output, the package type of the server to the client can be text / html text, or the GIF / JPEG graphic file, so before each transmission, we must inform the client to be transmitted. File types, generally defaults to "Text / HTML" type. For example <% response.contenttype = "image / jpeg"%>. 4) Response.cookies Used to set the value of cookies, syntax: Response.cookies [(key) | property] = information written. (Key's usage has been explained, not in the narrative) The cookies system has five attributes default, including Expires, Domain, Path (path), Secure, Haskeys (Judging whether Cookies is still There are other cookies texts. Such as: <% response.cookies ("type"). Expires = "SEP 9, 1998"%>. 5) Response.buffer is used to determine whether the information is transferred to the buffer. Because sometimes we want to send some intermediate information to the buffer, then continue working. When all processing work is completed, the information is output to the client. However, when the flush or end method is called during processing, the buffer content will be output. Response's other properties: Expires: Setting the web page to keep the length of the client browser. ExpireSabsolute: Set the date and time of the client browser.

Other methods of Response: AddHeader: Set the HTTP header of the HTML file. Appendtolog: Add a string at the end of the Web Server record file. CLEAR: Clears HTML output information in the buffer. End: Stop processing ASP files and returns the status. Flush: The HTML data of the buffer immediately immediately. 1.3 Server SERVER objects will provide you with some fixed SERVER-side methods and properties, including scripttimeout, mappath, and urlencode. Where ScriptTimeout is the properties of the server, specify the longest time execution of an ASP program, such as: server.scripttimeout = 200 (counting unit is second, default is 90 seconds). Mappath is a method of Server to convert the virtual path of the web server to the actual path. If Server.mAppath ("/") = C: / INETPUB / WWWROOT, the ASP will be regarded as path parameters "/" and "/". One thing to note here is that the system is just a real root output result of the Web Server, and does not check if there is a directory in the file system. Urlencode is another method of Server. This method will use the source string code as a target string according to the URL encoding principle, where the blank characters are replaced with " ". 1.4 Session Session is a very important object in ASP. When programming some traditional language, variables are related to global variables or local variables. However, the development on the Internet rarely mention this problem (except Java), because each HTML page is not related, all links will be disconnected. In ASP, it is different, we can define some global variables, the overall situation here refers to it can be used before the current browser is not closed. These variables can be defined in Global.asa. If your web application is automatically created with InterDev, you will find this file at the root directory; if it is not, you can create it yourself. Syntax: session. Properties | Method Generally established a new session object is a SET keyword, such as <% SET Session ("Variable Name") = value to be assigned. If you assign to the session variable, you will be stored in an array when reading because the system is considered an object (OBJECT). 1.5 Application Global.asa is a file used to define the session, Application, and Object objects, and the client cannot see the file. But this file must be placed on the root of the program, and the text cannot be marked in the text and the file name cannot be changed. Below is an example of a global.asa text.