|
||||||
How to Create a Simple VBScript CGI Web PageUsing VBScript for as a CGI Internet Programming LanguageVBScript is not normally considered as a cgi programming language. However, with just a little tweeking, it is as easy (if not easier) to use as Perl.
Microsoft VBScript is a very powerful and adaptable programming language. However, when it comes to web site programming there are limitations to VBScript. Not in it what it can do, but in what it is allowed to do. For example:
Obviously these tend to be show stoppers for VBScript programmers wanting to create applications for the Internet. The VBScript programmer, therefore, has very few options:
Or, on the other hand, they could just start creating CGI web pages with VBScript. CGI Web Pages and Web ServersCGI (Common Gateway Interface) web pages all contain code and they normally reside in the server's cgi-bin directory. However, that code is run on the server instead of in the user's web browser. The CGI pages simply returns an HTML output to the browser. And web servers, such as Apache, don't even care what language is to be uses to interpret the code. All they need to know is where to find the code interpreter, and that's done by setting the shebang line. Setting the Shebang Line for a VBScript CGI Web PageThe shebang line must always be the very first line of a CGI web page. It starts with a #! prefix and contains the location of the interpreter to be used. Obviously, in the case in VBScript this will be the Cscript executable. The shebang line should, in theory, be something like: #!c:\WINDOWS\system32\cscript.exe
However this actually outputs some text (which will stop the CGI page from working). The next stage is to turn off this text: #!c:\WINDOWS\system32\cscript.exe /nologo
At this point Cscript expects a file to be input, and this is the file that will contain the actual web programming code, for example the file could be called call_hello_world.vbs and would look like: #!c:\WINDOWS\system32\cscript.exe /nologo "C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin\hello_world.vbs"
The purpose of this first file is simply to call the second file (hello_world.vbs) with Cscript. It's this second file that contains the CGI code. A Simple VBScript CGI FileA VBScript CGI file must start with the line: wscript.echo "Content-type: text/html" & vbcrlf
This sets the header information for the web page. Any information for the body of the web page must be placed after that line, for example: wscript.echo "<h1>Hello World</h1>"
wscript.echo "This is is an output from VBScript"
And the end result of viewing "call_hello_world.vbs" can be seen in figure 1 at the bottom of this article. That end result is, of course, a CGI web page written completely in VBScript. Even so, many programmers may not be happy that each CGI web page will need to consist of two files and would refer just a single file. Therefore, that's covered in Professional CGI Web Development with VBScript.
The copyright of the article How to Create a Simple VBScript CGI Web Page in Windows Programming is owned by Mark Alexander Bain. Permission to republish How to Create a Simple VBScript CGI Web Page in print or online must be granted by the author in writing.
|
||||||
|
|
||||||
|
|
||||||