Scripting languages are an intermediate stage between HTML and programming languages such as Java, C++, and Visual Basic. HTML is generally used for formatting text and linking pages. Programming languages are generally used for giving a series of complex instructions to computers. While scripting languages can also be used to give instructions to computers, their syntax and rules are generally less rigid and intricate than those of compiled programming languages. Scripting languages focus on formatting text or calling and using compiled components written in a programming language.
Active Server Pages makes it possible for the Web developer to write complete procedures by using a variety of scripting languages. In fact, several scripting languages can be used within a single .asp file. In addition, because scripts are read and processed on the server side, the client browser that requests the .asp file does not need to support scripting.
You can use any scripting language for which the appropriate scripting engine is installed on your Web server. A scripting engine is a program that processes commands written in a particular language. Active Server Pages comes with two scripting engines: Microsoft Visual Basic Scripting Edition (VBScript) and Microsoft JScript. You can install and use engines for other scripting languages, such as REXX and Perl.
If you are already a Visual Basic programmer, you can immediately begin using VBScript, which is a subset of Visual Basic. If you are a Java, C, or C++ programmer, you may find that JScript syntax is familiar to you, even though JScript is not related to Java or C.
If you are familiar with another scripting language, such as REXX or Perl, you can obtain and install the appropriate scripting engine so that you can use the language you already know. Active Server Pages is an ActiveX scripting host; to use a language you must install a scripting engine that follows the ActiveX Scripting standard and resides as a COM (Component Object Model) object on the Web server.
The ASP primary scripting language is the language used to process commands inside the <% and %> delimiters. By default, the primary scripting language is VBScript. You can use any scripting language for which you have a script engine as the primary scripting language. You can set the primary scripting language on a page-by-page basis, or for all pages in an ASP application.
To set the primary scripting language for a single page, add the <%@ LANGUAGE %>
directive to the beginning of your .asp file. The syntax for this directive is:
<%@ LANGUAGE=ScriptingLanguage %>
where ScriptingLanguage
is the primary scripting language that you want to set for that particular page. The setting for a page overrides the global setting for all pages in the application.
Follow the guidelines for using an ASP directive; for more information, see Creating ASP Pages.
Note To use a language that does not support the Object.Method syntax as the primary scripting language, you must first create the LanguageEngines registry key.
To set the primary scripting language for all pages in an application, set the Default ASP Language property on the App Options tab in Internet Service Manager.
When using VBScript on the server with ASP, two VBScript features are disabled. Because Active Server Pages scripts are executed on the server, the VBScript statements that present user-interface elements, InputBox and MsgBox, are not supported. In addition, do not use the VBScript functions CreateObject and GetObject in server-side scripts. Use Server.CreateObject instead so that ASP can track the object instance. Objects created by CreateObject or GetObject cannot access the ASP built-in objects and cannot participate in transactions. The exception to this rule is when you are using the Admin Objects, and when you are using Java monikers. For more information, see Creating an Instance of a Java Class.
Because the processing of all ASP scripts is done on the server side, there is no need to include HTML comment tags to hide the scripts from browsers that do not support scripting, as is often done with client-side scripts. All ASP commands are processed before content is sent to the browser. You can use HTML comments to add remarks to an HTML page; comments are returned to the browser and are visible if the user views the source HTML.
Apostrophe-style comments are supported in VBScript. Unlike HTML comments, these are removed when the script is processed and are not sent to the browser.
<% 'This line and the following two are comments. 'The PrintTable function prints all 'the elements in an array. Call PrintTable(myarray()) %>
You cannot include a comment in an output expression. For example, the first line that follows will work, but the second line will not, because it begins with <%=
.
<% i = i +1 'this increments i. This script will work. %> <%= name 'this prints the variable name. This script will fail. %>
The //
comment characters are supported in JScript. These characters should be used on each comment line.
<% Call PrintDate %> <SCRIPT LANGUAGE=JScript RUNAT=Server> // This is a definition for the procedure PrintDate. function PrintDate() { var x x = new Date() // This line sends the current date to the browser, // translated to a string. Response.Write(x.toString()) } </SCRIPT>
VBScript is not case sensitive. For example, you can use either Request or request to refer to the ASP Request object. One consequence of case-insensitivity is that you cannot distinguish variable names by case. For example, you cannot create two separate variables named Color and color.
JScript is case sensitive. When you use JScript keywords in scripts, you must type the keyword exactly as shown in the reference page for that keyword. For example, using date instead of Date will cause an error. In JScript, the names of objects must be capitalized; method and property names can be any case. The case shown in this documentation for the ASP built-in objects will work in JScript commands.