Chapter 6 Writing DynaScripts
Overview of scripts
You can embed scripts in HTML templates to
control the information that the template provides to the user.
The PowerDynamo script language, DynaScript, uses a syntax much
like JavaScript. DynaScripts are interpreted by the application
server, and the results of that interpretation are passed on to
the Web server.
Script language summary
DynaScript has the following characteristics:
- Scripts are usually embedded in an HTML template.
You can also maintain a script as a separate file in the site, and
include it in other scripts or templates, allowing for code reuse
throughout the site.
- Because DynaScript is processed at
the application server, before the content is passed back to the
client, no client support for scripting is required
.
- Script statements and variables are
case-sensitive.
- You do not need to declare variables.
- Scripts can use the following datatypes:
- numeric
- logical (Boolean) true or false
- string
- null
- function
- object (methods and properties)
- Variables do not have a fixed datatype.
Datatype assignment occurs as needed when expressions are evaluated.
- Control statements such as
if
, while
, do-while
and for
have
a syntax similar to C and Java.
- You can create objects and define
their properties and methods.
- DynaScript includes several built-in
object types for working with databases, SQL, and HTML documents.
Using a server-side language
Scripting languages for the Internet are interpreted
at either the Web client or the Web server.
DynaScript is a server-side
language
that follows the ECMAScript standard (the standardized version of
JavaScript). DynaScript has a syntax much like JavaScript. There
are many uses for a server-side scripting language:
- Maintaining information through a series of client
accesses.
- Detailed control over formatting
of SQL queries.
- Error-checking for SQL statements.
For example, you can use scripts to check the success or failure
of a
delete
statement,
and to send an appropriate message to the Web client.
- Client-independent form validation.
It is quicker to validate entries in an HTML form at the Web client,
but validation at the server makes an HTML form client-independent.
- Server-side scripts can reduce the
amount of data being sent to the client.
There are some tasks that can be better performed
(or only performed) at the client side. For example, you cannot
direct HTML to different frames in a window from the server side.
Why a JavaScript-based language?
There are several languages commonly used for
Web-related tasks, including Java, JavaScript, and Perl. An ECMAScript
compatible language provides several advantages in PowerDynamo:
- While the strict typing and mandatory variable
declaration of Java are desirable for large-scale application development,
they can cause unnecessary overhead when developing small scripts
attached to a single Web page.
- The object-based structure of ECMAScript
allows more readable and maintainable code than languages with many
special features, such as Perl.
Implementing scripts
You can implement DynaScript in several ways:
- You can embed Scripts in HTML templates. This
is the most straightforward way of using scripts, and how most of
the examples in this chapter are presented.
- You can write a script that generates
an entire document (complete with HTML tags and queries). The Web
client can request the script itself (rather than a separate HTML
document), and the application server interprets the script to generate
both the HTML and the query output to return to the client.
- You can group common functions or
class definitions into a separate script. You can then import this
script into any other script or template that requires those functions
or classes.
Copyright © 1999 Sybase, Inc. All rights reserved.
|
|