A scripting language is somewhere between HTML and programming languages like Java, C++, and Visual Basic. HTML is commonly used to format text and link web pages. Programming languages are often used to send a complex sequence of instructions to a computer. Scripting languages can also be used to send instructions to computers, but their syntax and rules are not as strict and complex as compilable programming languages. Scripting languages are primarily used for formatting text and using compiled components written in programming languages.
Active Server Pages makes it possible for Web developers to write complete processes in a variety of scripting languages. In fact, multiple scripting languages can be used within a single .asp file. Additionally, because scripts are read and processed on the server side, the client browser requesting the .asp file does not need to support scripts.
You can use any scripting language for which a corresponding scripting engine is installed on the Web server. A script engine is a program that processes commands written in a certain language. Active Server Pages comes with two scripting engines: Microsoft Visual Basic Scripting Edition (VBScript) and Microsoft JScript. You can also install and use other scripting language engines, such as REXX and Perl.
If you are already a Visual Basic programmer, you can immediately use VBScript, which is a subset of Visual Basic. If you are a Java, C, or C++ programmer, you will find that JScript syntax is familiar to you, although 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 corresponding scripting engine so that you can use the scripting language you are familiar with. Active Server Pages is a host for ActiveX scripts. To use a language, a scripting engine must be installed, which must adhere to the ActiveX scripting standard and reside on the Web server as a COM (Component Object Model) object.
Set the main script language
The ASP main scripting language is the language used to process commands inside the delimiters <% and %>. By default, the primary scripting language is VBScript. You can use any scripting language with a scripting engine as the main scripting language. You can set the primary script language on a page-by-page basis, or you can set the primary script language for all pages in an ASP application.
Set the language for a page
To set the main script language for a single page, add the <%@ LANGUAGE %> directive to the beginning of the .asp file. The syntax of this directive is:
<%@ LANGUAGE=ScriptingLanguage %>
Among them, ScriptingLanguage is the main scripting language of the page you set. If set for a page, it will ignore global settings for all pages in the application.
Please follow the instructions for using ASP directives.
Note To use a language that does not support Object.Method syntax as the main scripting language, you must first create the LanguageEngines registry key.
Set the language for the application
In an application, to set the main scripting language for all pages, set the Default ASP Language property on the App Options tab of the Internet Services Manager.
Using VBScript and JScript on the server
When using VBScript via ASP on the server side, two VBScript features are disabled. Because Active Server Pages scripts are executed on the server side, the VBScript statements InputBox and MsgBox that represent elements of the user interface will not be supported. In addition, in server-side scripts, please do not use the VBScript functions CreateObject and GetObject. Instead, use Server.CreateObject so that ASP can track object instances. Objects created with CreateObject or GetObject cannot access ASP built-in objects and cannot participate in transactions. An exception to this rule is if you are using Admin objects and Java monikers.
Contains comments
Because ASP scripts are processed on the server side, even if the client's browser does not support the scripting language, there is no need to hide the script by including HTML comment tags, as is usually the case with client-side scripts. All ASP commands have been processed before the content is sent to the browser. You can add comments to HTML pages using HTML comments. The comment will be returned to the browser and will be visible if the user browses the HTML source file.
VBScript comments
VBScript supports apostrophe comments. Unlike HTML comments, they are removed when the script is processed rather than being 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())
%>
Output expressions cannot include comments. For example, the first line below will work fine, but the second line won't because it starts with <%=.
<% i = i +1 'this increments i. This script will work. %>
<%= name 'this prints the variable name. This script will fail. %>
JScript comments
JScript supports the // comment character. This comment character must be used in every 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>
Case sensitivity
VBScript is not case sensitive. For example, you can use Request or request to refer to the ASP Request object. A consequence of case insensitivity is that you cannot use case to distinguish variable names. For example, you cannot create two separate variables named Color and color.
JScript is case sensitive. To use JScript keywords in scripts, they must be written in the case shown on the reference page. For example, using date instead of Date will result in an error. In JScript, object names must be in uppercase; method names and property names can be in uppercase or lowercase. The case of ASP built-in objects shown in this article will work fine in JScript commands.