Americas

  • United States

Scripting Active Server Pages

Opinion
Dec 09, 20024 mins
Networking

A look at scripting languages that can be used wth Active Server Pages.

A correction to our last correction is in order: Three weeks ago we wrote that “the Windows Task Scheduler . . . only allows a minimum repeat interval of 24 hours,” and we were wrong. We corrected that last week, and then we wrote that even so, we couldn’t schedule “the second Tuesday of every month” in the scheduler. Subsequently, we’ve discovered that we could, so we are shamefaced. The only thing we can’t figure out now is how to schedule “the third Thursday of March in leap years.”

We started this series of columns on Microsoft’s Active Server Page (ASP) technology by discussing the issues of Common Gateway Interface programs compared with Dynamic Link Libraries. And we took a brief diversion into the technology of thread-safe programming, a requirement for re-entrant DLLs (that is, DLLs that can be called by and provide service to multiple processes).

Last week in our second part  we showed, in the process of explaining the basics of ASP, a pathetic piece of code that merely inserts the Web server’s time in a Web page, as in: “Hello World! The server’s time is now 3:44:53 PM.” We are sure you could hardly contain yourselves.

That ASP code was written in VBScript but could have been written in any scripting language whose scripting engine conformed to the Microsoft ActiveX object model. The most common alternative is Jscript, Microsoft’s implementation of JavaScript. JScript can be used in ASP pages by itself or with VBScript.

Another popular scripting language that can be used with ASP is REXX – notably the freeware version called Regina REXX. And if that isn’t enough, you can use Perl in the guise of PerlScript.

If you want a scripting language other than VBScript to be the default (at least, as it is under Microsoft Internet Information Server [IIS]) then you need to declare so:

The construction “" indicates to the ASP interpreter that the following will be a "preprocessing directive" -- in the above case, to change the default scripting interpreter. There are other directives, such as ENABLEEXPRESSIONSTATE (set to TRUE -- the default -- if user session information is to be stored, FALSE if not); and LCID to set the locale identifier (for example, France is 1036).

With one exception, the standard server-side includes — preprocessing directives that support included values such as file modification dates, insert the output of a command line application, include a file and so on — aren’t allowed in ASP pages. Server-side includes look like comments and the one that is allowed is “#include“, which, as you might guess, inserts the contents of a file in the ASP page. For example:

This directive is replaced on the fly by the IIS with the contents of the included file. The keyword”file” indicates that the path to the file is relative to the current path (the alternative is “virtual,” which indicates a full virtual path to the file).

The inclusion is carried out before the ASP parser executes the scripts on the page (otherwise, included files could be skipped causing indeterminate results if they contained ASP code). This means that you can’t dynamically change which page is included — so don’t try.

Now let’s start a script. To do this we use the following tags:

In the opening tag we can specify the scripting language to be used, which lets us indulge in mixed-language ASP. We can specify that the code is to be run only at the server with the RUNAT attribute. Thus:

The RUNAT attribute is important, as it ensures that the script is executed at the server and not sent to the client.

mark_gibbs

Mark Gibbs is an author, journalist, and man of mystery. His writing for Network World is widely considered to be vastly underpaid. For more than 30 years, Gibbs has consulted, lectured, and authored numerous articles and books about networking, information technology, and the social and political issues surrounding them. His complete bio can be found at http://gibbs.com/mgbio

More from this author