|
In the preceding parts of The JavaScript Chronicles we've concentrated on using
JavaScript on web pages or Client Side JavaScript. There is
also another application of JavaScript, with its own
commands, capabilities and syntax, Server-Side JavaScript.
|
Introduction to Server Side JavaScript
In the preceding tutorials, we've concentrated on using
JavaScript on web pages - Client Side JavaScript. There is
also another application of JavaScript, with its own
commands, capabilities and syntax - Server-Side JavaScript.
Netscape has released a set of commands that are used on its
Enterprise Web Server, called Netscape's Server Side
Additions. The use of Server Side JavaScript is mostly
limited to maintaining user sessions and handling user
requests and form submissions. Cookies are huge with Server
Side JavaScript.
While Netscape was releasing its own line of Web Servers,
Microsoft was developing something of its own, called Active
Server Pages. These Active Server Pages perform much the
same as server side JavaScript on the Netscape Enterprise
servers, but differ enough to require a separate set of
tutorials. Microsoft's Active Server Pages (ASP) won't be
discussed here, only Server Side JavaScript implemented the
Netscape way.
Server Side versus Client Side
When working with client side JavaScript, everything was
scripted. That is, it wasn't run through a compiler before
it was able to be executed. The browser just reads it and
acts upon your instructions. Server side JavaScript differs
from client side in that it must be compiled into a byte-
code file, usually with a .web extension. That is pretty
much the major difference you'll find in the actual process
of deploying your script. The commands differ of course, but
this is the big difference.
Within an HTML page, your script was contained within the
opening and closing HTML SCRIPT tags. Leaving out these tags
resulted in the browser rendering your script as just more
textual content to be displayed in the browser window. With
server side JavaScript, the SCRIPT tags are replaced with
opening and closing SERVER tags (<SERVER> and
</SERVER>). You can see that there is no huge
difference here.
Some of the major difference you'll find in dealing with
server side JavaScript is the ability to send mail, access
and write to multiple database's, access and manage user
driven data requests, and the specific handling of user
provided data. You'll be the king of your domain!! (pun
intended).
You'll also notice that you'll have to mesh your client
side scripting with your server side scripting - some client
side commands won't work on the server side. An upcoming
Server Side JavaScript Tutorial will address these issues
and discuss every available command in depth, with examples.
Compiling Your Server Side Script
With the Netscape Enterprise Web Server comes what is called
the JavaScript Application Compiler, or JSAC for short. This
application is a command line utility that enables you to
compile your script into the byte code format required by
the server. It works something like the Java .jar files
available to the Netscape Navigator browser. The files
containing your server side script as well as any external
JavaScript files of .js extension are included in this
compiled file. As mentioned earlier, the compiled file is
given a .web extension. The JSAC application has many
parameters to meet your requirements, as the following list
shows.
- -a version - This switch allows you to specify the
version of the JavaScript Interpreter to use when compiling
your server side script. Currently the only option is for
JavaScript version 1.2 - "javascript1.2" (exactly, no
quotes, no spaces).
- -c - This switch is used to verify the script you are
about to compile. Any errors thrown by the script will be
reported. A compiled .web file is not generated when this
switch is used. Also, do not use this switch with the -o
switch.
- -d - This switch is used to display the JavaScript
script contained within all of the files which are to be
compiled into a .web file. Very useful to verify that you've
included the proper files to be compiled.
- -f filelist - This switch is used to give JSAC a list
(.txt file only, please) of all of the files to include in
the compiled .web file. The file names should be separated
with a space. Any file names that have a space in them
should be stated within quotes to avoid any confusion on the
part of the JSAC Application.
- -h - This switch will display the help files associated
with JSAC. This switch should be used on its own, with no
other switches.
- -i input file - This switch is used to give the name of
a single .html file to be used for the compilation into a
.web file. Note that you should use the -f switch to specify
multiple files.
- -0 output file - This switch is used to specify the name
of the file that is to be compiled. It is the compiled file
name of .web extension. Do not use this switch with the -c
switch.
- -p path - This switch is used to specify the root
directory from which all of the relative filenames you
provide will be referenced from. It is similar in
functionality to the HTML BASE tag.
- -r error file - This switch is used to specify the
filename and location of a file which will contain all of
the errors (if any) which occurred during the compilation of
your server side script into a .web file.
- -v - This switch will display a "verbose" description of
all of the operations which occurred during the compilation
of your script into a .web file.
You may use these switches together in combinations, with
the exception of the -c and -o switches. You can see that
the creators of the Enterprise Web Server have included a
lot of switches to make your use of their product easier and
less of a headache. If the switches don't quite make sense,
take a look at the following command line instructions given
to the JSAC Application.
jsac -o sscompiled.web -v fileOne.html fileTwo.html external.js -r errors.log
The above commands tell JSAC to compile the files
fileOne.html fileTwo.html external.js into the .web file
sscompiled.web. Notice the -v switch has been used to tell
you what has been happening, switching on the verbose
feature. The -r switch was used to turn on the function that
writes any errors to the file you specify, in this case the
errors.log file. Simple.
Pattern Matching - The RegExp Object - Continued
The JavaScript Chronicles
Database Connectivity via Server Side
The JavaScript Chronicles
JavaScript Introduction
Part 2: Data Types
Part 3: Arrays
Part 4: Operators
Part 5: Conditional Statements
Part 6: JavaScript Functions
Part 7: Pattern Matching - The RegExp Object
Part 8: Introduction to Server Side JavaScript
Part 9: Server Side JavaScript Mail Sending
Part 10: Server Side JavaScript and File Manipulation
Part 11: Working with Forms in JavaScript
Part 12: Getting to Know Dynamic HTML
|