Using scripting languages in ASP

Source: Internet
Author: User
Tags html comment html tags object model
The scripting language is somewhere between HTML and java,c++ and VisualBasic programming languages. HTML is typically used to format and link text. Programming languages are often used to send a series of complex instructions to a machine. The scripting language is somewhere between the two but its functions are more like the programming language. The biggest difference between it and the programming language is that the latter's syntax and rules are stricter and more complex.

Using the scripting language on the server side requires the scripting engine to be installed on the server side. The scripting engine is a COM (Component Object model) object that is used to process scripts. ASP provides the host environment for the scripting engine and hands the script in the. asp file to the script engine for processing. For each scripting language used in the. asp file, install their corresponding scripting engine on the Web server. The default language in ASP is VBScript, so you don't have to worry about installing VBScript's scripting engine, and when you're done installing activeserverpages, he's already there. There is no need to worry about using JScript. However, to use some of the less common scripting languages, you may need to install the appropriate scripting engine.

ASP enables Web developers to write programs in a variety of scripting languages without worrying about browser support. In fact, you can use a variety of scripting languages in an. asp file, as long as you use HTML tags at the beginning of each script to mark the scripting language.

VBScript is the default primary scripting language. The main scripting language is used within delimiters <% and%>, and you can use any valid VBScript command within the delimiter, and the ASP will process the commands in VBScript. In fact, you can set any scripting language as the primary scripting language. You can get tired of it. A page-by-page setting, you can also set a script language as the primary scripting language for all pages on your Web server. If you want to set a scripting language as the lead language on a page, just add the following command at the beginning of the. asp file.

% @LANGUAGE =scriptinglanguage% , where scriptinglanguage represents the main scripting language you want to set up. If you want to set a script language as the main scripting language for all pages on your Web server, you need to use a powerful registereditor (register editor, Regedit.exe), and the registration path for the ASP registration parameters is as follows:
Hkey_local_ Machine\system
\CurrentControlSet
\services
\w3svc
\asp
\parameters
where, The default value of the registry key Defaultscriptlanguage is "VBScript", which is changed to the scripting language you want to set. For example, if you want to set JScript as the protagonist in this language, you can change the value of the registry key defaultscriptlanguage to "JScript". Mixing different scripting languages in the same. asp file is one of the fascinating features of ASP. In this way, you can play a variety of different scripting languages in different aspects of the advantages. You can use different scripting languages to write different scripting programs to do different jobs.

A scripting program is actually a set of script commands that perform a specific task. If you frequently perform a specific set of tasks, you can define it as a program and then call it again and again. Programs are written in the rules of a specific scripting language between labels . Of course, if you write a program in the main scripting language, it can be written between the delimiter <% and the%>. If your program is only called on a page, just put it on this page, and if you want to call some programs on multiple pages, you can put them in a separate. asp file and include that. asp file in each of the. asp pages that you want to call these programs.
To include additional files in the. asp page, use the following syntax:
!--#INCLUDEVIRTUAL file= "filename"-->
Among them, filename is the file you want to include. Keyword virtual and file optional, virtual represents the file to be included in a virtual directory (the directory is a Web share), and file represents the files to include in a current file-related directory. Examples are as follows: Suppose you have two Web shared directories Dir1 and DIR2, directories Dir1 files file11.asp and file12.asp, directory Dir2 with file File2, To include file2.asp in the file file11.asp, add the following command to the file file11.asp:

The!--includevirtual= "dir2/file2.asp"-->


To include file12.asp in the file11.asp, add the following command to the file file11.asp:
The!--includefile= "file12.asp"-->
Or you may use the following order:
The!--includevirtual= "dir1/file12.asp"-->
The program is written well, how to call it? If you use a scripting language that is VBScript, just a simple keyword call plus the program name is OK. If the program you want to invoke has parameters, enclose the arguments in parentheses. If you omit the keyword call, the parentheses will also be omitted. The following example shows the creation and invocation of a program in two different scripting languages (VBScript and JScript) in the same ASP page.
<HTML>
<HEAD>
<TITLE> Usedifferentscriptinsamepage </TITLE>
</HEAD>
<bodybgcolor= "#FFFFFF" >
<TABLE>
<%CallEcho%>
</TABLE>
<%CallPrintDate%>
</BODY>
</HTML>


Subecho
Response.write_
" Name Value "
Setparams=request.querystring
Foreachpinparams
Response.Write " " &p& " " &_
Params (P) & " "
Next
Endsub


Functionprintdate ()
{
Varx
X=newdate ()
Response.Write (X.tostring ())
}


When you use VBScript on the server side, there are two VBScript features that are not available. Because scripts are executed on the server side, InputBox and MsgBox, which provide the user interface in VBScript, are not supported. In addition, the functions of VBScript CreateObject and GetObject are not supported.
Because all ASP scripts are executed on the server side, there is no need to hide the script with HTML comment tags for browsers that do not support scripting, as with client script. All script commands are processed before the content is sent to the browser. But you can use annotations between script commands or in programs. As basic, there are two forms of annotation available in VBScript: REM or single quotes. As shown in the following example:
<%
Remthislineandthefollowinglinearecomments
' Printgreetingingreen
Greeting= "howareyou!"
<fontcolor= "GREEN" > <%=greeting%>
%>
Annotate in JScript with "//" as shown in the following example:
<%CallPrintDate%>
<SCRIPTLANGUAGE=JScriptRUNAT=Server>
Functionprintdate ()
{
Varx
X=newdate ()
Response.Write (X.getdate ())
}
Thisisadefinitionfortheprocedureprintdate.
Thisprocedurewillsendthecurrentdate
Totheclient-sidebrowser.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.