Recommended: ASP programming session skills Anyone who has written a slightly larger ASP knows that Session is really useful. It can be used to record user-owned data variables, which is both safe and convenient. But do you really know how Session works? Perhaps after you understand, you will never dare to use this love-hate object again. Although the method of replacing it is a bit troublesome, but it is still a long time
Variables are used to store information.
If a variable is declared outside the subroutine, the variable can be changed by any script in the ASP file. If a variable is declared in a subroutine, it will be created and revoked every time the subroutine is executed.
Example:
Declare variables
The following is the quoted content: <html> <body> <% dim name name=Donald Duck response.write(My name is: & name) %> </body> </html> |
Variables are used to store information. This example demonstrates how to declare a variable, assign a value to a variable, and use this variable in a program
Declare an array
The following is the quoted content: <html> <body> <% Dim fname(5),i fname(0) = George fname(1) = John fname(2) = Thomas fname(3) = James fname(4) = Adrew fname(5) = Martin For i = 0 to 5 response.write(fname(i) & <br />) Next %> </body> </html> |
Arrays are used to store a series of related data items. This example demonstrates how to declare an array that stores names.
Looping to generate HTML titles
The following is the quoted content: <html> <body> <% dim i for i=1 to 6 response.write(<h & i & >Header & i & </h & i & >) next %> </body> </html> |
How to loop to generate 6 different HTML titles.
Make time-based greetings with Vbscript
The following is the quoted content: <html> <body> <% dim h h=hour(now()) response.write(<p> & now()) response.write( (Beijing Time) </p>) If h<12 then response.write(Good Morning!) else response.write(Good day!) end if %> </body> </html> |
This example will display different messages to the user according to the server time.
Make time-based greetings using JavaScript
The following is the quoted content: <%@ language=javascript %> <html> <body> <% var d=new Date() var h=d.getHours() Response.Write(<p>) Response.Write(d (Beijing Time)) Response.Write(</p>) if (h<12) { Response.Write(Good Morning!) } else { Response.Write(Good day!) } %> </body> </html> |
This example is the same as above, but the syntax is different.
The lifetime of variables
Variables declared outside of the subroutine can be accessed and modified by any script in the ASP file.
Variables declared in subroutines are created and revoked only when the subroutine is executed each time. This variable cannot be accessed and modified by scripts outside the subroutine.
To declare variables for use by multiple ASP files, declare the variable as a session variable or an application variable.
Session variable
The Session variable is used to store information for a single user and is valid for all pages in one application. Typical data stored in session is a name, id, or parameter.
Application variables
The Application variable is also valid for all pages in an application. Application variables are used to store information about all users in a specific application.
Share: Calling SQL Server views and stored procedures in ASP 1. Preface ASP (Active Server Pages) is a server-side scripting environment, which is supported by Microsoft's IIS3.0 or above. It can be used to create dynamic web pages or to generate powerful web applications. An ASP page is a file that includes HTML tags, text, and script commands. ASP pages can call ActiveX components to perform tasks such as connecting to a number