Sideway BICK BlogSideway BICK BLOG from Sideway

A Sideway to Sideway Home

Link:http://output.to/sideway/default.asp?qno=121200003

Script, Scripting Language, ASP Scripting,

Scripting

ASP is only a server side scripting technology along with some fundamental interface elements from Microsoft.com for running script on the server side to create HTML content dynamically. In other words, ASP is only a scripting host for the supported scripting language to provide the interactivity required for a dynamic web application solution on the server side. Script is a small program or a series of instructions written for a command interpreter to interact with the scripting host. A scripting language is needed to use as the programming language for web application development. The scripting language allows the web site builder to customization their web site by making use of the conditional and looping statements, and the built-in functions. The ASP engine of Internet Information Server provides native support for both Microsoft VBScript and JScript. Both VBScript and JScript can be used as the scripting language for ASP. Besides VBScript and JScript, other third-party ActiveX compliant Scripting engines can also be used. The key feature of these ActiveX Scripting engines is the capability of calling ActiveX objects and the built-in ASP objects. The default scripting language is VBScript.

ASP Server-Side Scripting

For the client-side scripting,  all script can be placed within the HTML document by the <script> element. That is all script is enclosed by <script></script> tags of the <script> element. The included scripting code in the HTML document will sent to the browser together with the HTML contents. But for the ASP server-side scripting, the file extension of the HTML document should be ended with ".asp" and all ASP command must be delimited with <%...%> otherwise the ASP code or scripts will not be interpreted by the ASP engine. Since the code delimited with <%...%> will be interpred before sending to the browser, the server-side script which compatible with the client-side scripting language can also be placed inside the client-side script. Besides the <script> element with "runat" attribute equal to "server" can also be interpreted as a server-side only function which can be work with the ASP script at the server-side. However, since the server-side <script> element is already running in the server-side scripting environment, the using of delimiters <%...%> in the server-side <script> element will become a syntax error.  Therefore the delimiter "<%" is to pass the control of code interpretation to the ASP engine of the current default scripting and the delimiter "%>" is to return the control of code interpretation to the web server.

ASP script command:

<%strName = "ABCDE" : intCount = 3%>
Cut "<%=strName%>" to "<%=strCutName(strName)%>".
<script language = "vbscript" runat = "server">
function strCutName(strName)
strCutName = Right(strName, 3)
end function
</script>
<script type = "text/vbscript">
document.write(Right("<%=strName%>", <%=intCount%>))
end function
</script>

HTTP response output:

Cut "ABCDE" to "CDE".

<script type = "text/vbscript">
document.write(Right("ABCDE", 3))
</script>

HTML web page output in Internet Explorer:  

Cut "ABCDE" to "CDE". CDE

Scripting Language

The default scripting language of the ASP script programming is VBScript. The default scripting language of ASP engine can also be specified by the preprocessor ASP directive, @LANGUAGE. Since the default scripting language is changed, the ASP engine should return  the control of code interpretation to the web server before the new default scripting language becomes activated, i.e. end the preprocessor ASP directive by "%>" becore continue with other script.

ASP script command:

<%@ language="jscript"%>
<%var strName = "ABCDE";%>
Cut "<%=strName%>" into"<%=strName.slice(0,2)%>"
and "<%=strCutName(strName)%>".
<script language = "vbscript" runat = "server">
function strCutName(strName)
strCutName = Right(strName, 3)
end function
</script>

HTTP response output:

Cut "ABCDE" into "AB"
and "CDE".

HTML web page ouput:

Cut "ABCDE" into "AB" and "CDE".

In general, more than one scripting language can be used for the entire ASP application. For example, VBScript in server-side code and JavaScript on the client-side code. Besides server-side script other than the default scripting language can also be used with the HTML document using the <SCRIPT> element with the corresponding scripting language. Whenever there is preprocessor ASP directive, the ASP engine will process first. If the @LANGUAGE directive is present, the ASP engine will set the default scripting language accordingly. Then the ASP engine will first interpret all script in <SCRIPT> element with non-default scripting language before continue with the code after the preprocessor ASP directive.  All script in <SCRIPT> element with default scripting language will be interpretted after processing the whole HTML document. Because of the unexpected sequence of processing the <SCRIPT> element due to the complexity of the script arranged by the ASP engine, the <SCRIPT> element is usually used for containing procedures and functions only. Besides, the client-side script will be interpreted on the client browser whenever necessary.

ASP script command:

<%@ language="jscript"%>
<%strName = "ABCDE"%>
Cut "<%=strName%>" into "<%//=left(strName,2)%>
<%=strName.slice(0,2)%>" and "<%=strCutName(strName)%>".
<script language="vbscript" runat="server">Response.Write("V1 ")</script>
<%="L1 "%>
Cut "<%=strName%>" to "<%=strCutJName(strName)%>".
<script language="jscript" runat="server"> Response.Write("J1 ")</script>
<script language="vbscript" runat="server">Response.Write("V2 ")</script>
<%Response.Write("L2 ")%>
<script language="jscript" runat="server"> Response.Write("J2 ")</script>
<script language = "vbscript" runat = "server">
Response.Write("V3 ")
function strCutName(strName)
strCutName = Right(strName, 3)
end function
</script>
<script language = "jscript" runat = "server">
function strCutJName(strName) {return strName.slice(2);}
Response.Write("J3 ")
</script>
End

HTTP response output:

V1 V2 V3
Cut "ABCDE" into "AB" and "CDE".
L1
Cut "ABCDE" to "CDE".
L2
End J1 J2 J3 ".

HTML web page ouput:

V1 V2 V3 Cut "ABCDE" into "AB" and "CDE". L1 Cut "ABCDE" to "CDE". L2 End J1 J2 J3

Syntax

Since more than one scripting language can be used to build the ASP code, the syntax of ASP page is highly depending on the scripting language used in writing the web application. Aparted from the syntax of scripting language, there are also some basic rules for constructing correctly structured ASP pages.

  • An ASP page file is a text file. There is special limitation on the encoding of the file.

  • The filename extension of an ASP page file should be ".asp" except the global control setting  file , i.e Global.asa for an web application

  •  The file contents can be text, HTML tags, or server-side scripts.

  • A #include directive enclosed in a HTML comment element, e.g. <!-- #include... --> outside of the delimiter <%...%> for inserting the content of one file into the file before interpreted by the web server.

  • All ASP scripts are enlcosed between the delimiter <%...%>. All enclosed scripts will be interpreted by the ASP engine while the others will remain unchanged as original plain text and HTML tags.

  • The HTML <script> element can also be made compatible with the ASP technology by adding extra attributes, i.e. <script language="..." runat=""server">...</script>.

  • @processing directives enclosed by the delimiter <%@...%> placing at the first line of an ASP file to pass information to the web servre on how to process the ASP file..

  • An output directive enclosed by the delimiter <%= expression %>, which is equivalent to the Response.Write method, to displays the result of an expression in the form of plain text.

  • ActiveX Scripting enclosed by the delimiter <%...%> is the fundamental interface elements of the ASP technology from Microsoft. The key feature of these ActiveX Scripting code elements is the capability of calling ActiveX components, ActiveX objects and the built-in ASP objects. Each Active X elements have their only ActiveX scripting syntax.

  • ASP element

    • The delimiters "<%" and "%>" can be either on the same line with the scripts

      <% Response.Write ("<h1>ASP Sample</h1>") %>

      or on an individual line.

      <%
      Response.Write ("<h1>ASP Sample</h1>")
      %>

    • the space between the delimiter and script is not necessary because ASP engine removes white space including spaces, tabs, returns, and line feeds from both VBScript and JScript command of an ASP file. But for other scripting languages, the ASP engine preserves white space so that scripting languages dependent upon position or indentation can be interpreted correctly.

      <%Response.Write ("<h1>ASP Sample</h1>")%>

    • Comment the script between the delimiters can be done by placing an apostrophe(') at the beginning of a line. And it is better to place another apostrophe(') at the end of a line for better compatibility with JScript. Unlike the HTML comments and client-side  scripting comments, the server-side comments are removed by the interpreter during processing and no server-side comment will be sent to the browser.

      <% ' comment '%>

    • A line break can be used to indicate the end of a script command in both VBScript and JScript command of an ASP file.

      <%
      Response.Write ("<h1>ASP Sample</h1>")
      Response.Write ("<h2>ASP Statement</h1>")
      %>

Previous Month  DEC  2012  Next Month
SMTWTFS
1
2345678
9101112131415
16171819202122
23242526272829
3031

Previous Month  JAN  2010  Next Month
SMTWTFS
12
3456789
10111213141516
17181920212223
24252627282930
31

Sideway BICK Blog

16/12


Copyright © 2000-2020 Sideway . All rights reserved Disclaimerslast modified on 26 January 2013