The scripting language is between HTML, Java, C ++, Visual Basic, and other programming languages. HTML is usually used to format and link text. Programming languages are usually used to send a series of complex commands to machines. The scripting language is between the two, but its functions and programming languages are more similar. The biggest difference between it and programming languages is that the latter's syntax and rules are stricter and more complex.
To use the script language on the server, you must install the script engine on the server. The script engine is a COM (Component Object Model) object used to process scripts. ASP provides a host environment for the script engine and submits the scripts in the. asp file to the script engine for processing. For each script language used in the. asp file, their corresponding script engine must be installed on the Web server. The default language in ASP is VBScript, so you don't have to worry about installing the script engine of VBScript. When you have installed activeserverpages, it already exists. You don't have to worry about using JScript. However, you may need to install the corresponding script engine if you want to use some less commonly used scripting languages.
ASP allows web developers to write programs in various scripting languages without worrying about browser support. In fact, you can use Multiple scripting languages in A. asp file, as long as you mark the scripting language at the beginning of each script program with HTML tags.
VBScript is the default main script language. The main script language is used within the delimiters <% and %>. You can use any valid VBScript commands within the delimiters. asp processes these commands according to VBScript. In fact, you can set any scripting language as the main scripting language. You can configure one page at a time, or set a script language as the main script language for all pages on your Web server. If you want to set a script language as the main character language on a page, simply add the following command at the beginning of the. asp file.
<% @ Language = scriptinglanguage %> scriptinglanguage indicates the main script language you want to set. The registration path of ASP registration parameters is as follows:
HKEY_LOCAL_MACHINE/System
/CurrentControlSet
/Services
/W3svc
/Asp
/Parameters
The default value of the registry defascriptlanguage is "VBScript", and you can change it to the script language you want to set. For example, if you want to set JScript as the main language, change the defaultscriptlanguage value of the registry entry to "jscript. Mixing different scripting languages in the same. asp file is one of ASP's fascinating features. In this way, you can take advantage of different scripting languages in different aspects. You can write different script programs in different scripting languages to complete different tasks.
A script is actually a group of script commands that execute specific tasks. If you often want to execute a specific set of tasks, you can define them as programs and then call them again. The program should be written between the tag <SCRIPT> and </SCRIPT> according to the rules of the specific script language. Of course, if you write a program in the main scripting language, you can also write it between the delimiters <% and %>. If your program is called on only one page, you can put it on this page. If you want to call some programs on multiple pages, you can put these programs in a separate one. ASP file, and then in each. the. ASP file inclusion.
To include other files on the. ASP page, use the following syntax:
<! -- # Includevirtual file = "FILENAME" -->
Here, filename is the file you want to include. You can select either the keyword virtual or file. Virtual indicates that the file to be included is in a virtual directory (which is a Web shared directory ), file indicates that the file to be included is in a directory related to the current file. Example: assume that you have two web shared directories dir1 and dir2. The dir1 contains files file11.asp and file12.asp. The dir2 directory contains files file2. To include file2.asp in the file file11.asp, add the following command to the file file11.asp:
<! -- Includevirtual = "dir2/file2.asp" -->
To include file12.asp in file11.asp, add the following command to file11.asp:
<! -- Includefile = "file12.asp" -->
You can also use the following command:
<! -- Includevirtual = "dir1/file12.asp" -->
After the program is written, how can I call it? If you use VBscript, you only need a simple keyword call and a program name. If the program you want to call has parameters, enclose the parameters in brackets. If you omit the keyword call, the brackets should also be omitted. The following example shows how to use two different scripting languages (VBScript and JScript) to create and call programs on the same ASP page.
<HTML>
<Head>
<Title> usedifferentscriptinsamepage </title>
</Head>
<Bodybgcolor = "# ffffff">
<Table>
<% Callecho %>
</Table>
<% Callprintdate %>
</Body>
</Html>
<Scriptlanguage = vbscriptrunat = Server>
Subecho
Response. Write _
"<Tr> <TD> name </TD> <TD> value </TD> </tr>"
Setparams = request. querystring
Foreachpinparams
Response. Write "<tr> <TD>" & P & "</TD> <TD> "&_
Params (p) & "</TD> </tr>"
Next
Endsub
</SCRIPT>
<Scriptlanguage = jscriptrunat = Server>
Functionprintdate ()
{
Varx
X = newdate ()
Response. Write (X. tostring ())
}
</SCRIPT>
When Using VBScript on the server side, two VBScript features are unavailable. Because the script is executed on the server, the inputbox and msgbox on the user interface provided by VBScript are not supported. In addition, VBScript functions Createobject and GetObject are not supported.
Because all ASP scripts are executed on the server, you do not need to hide the scripts with HTML annotations for browsers that do not support scripts as you did when using client scripts. All script commands are processed before the content is sent to the browser. However, you can use annotations between script commands or programs. Like Basic, there are two forms of annotations available in VBScript: REM or single quotes. For example:
<%
Remthislineandthefollowinglinearecomments
'Printgreetingingreen
Greeting = "howareyou! "
<Fontcolor = "green"> <% = greeting %>
%>
Note "//" In JScript, as shown in the following example:
<% Callprintdate %>
<Scriptlanguage = jscriptrunat = Server>
Functionprintdate ()
{
Varx
X = newdate ()
Response. Write (X. getdate ())
}
// Thisisadefinitionfortheprocedureprintdate.
// Thisprocedurewillsendthecurrentdate
// Totheclient-sidebrowser.