Working with server scripts
You can embed server scripts in your HTML pages or place them
in separate script files. You can import a server script file that
contains code for processing by the application server you specify,
or you can include a server script file if its contents need only to be redirected,
without modification, from the server to client-side browsers.
For Web site targets, if you want your server scripts to be platform-independent,
you need to write in JavaScript. JavaScript is supported by PowerDynamo
and ASP. For JSP targets, you typically write server scripts in
Java.
Using script files
By storing code in separate script files, you can centralize
common functions, thereby simplifying development and maintenance.
Once you have created a script file, you can import this file into
Web pages and into other script files, or you can insert the file
contents on a page as embedded script. You can use the standalone
Script editor to create separate script files.
For information on using the standalone Script editor, see Chapter 6, “Writing Scripts “.
Embedding server scripts
If you want server scripts to appear within an HTML page,
you can write them in the integrated Script editor or insert them
from a script file.
Embedded server script is delimited by HTML tags that can
differ depending on the object model you are using. You can create
an embedded server script for deployment to a specific application
server or for platform-independent deployment.
When you create a server script in the integrated Script editor,
you can make the following choices for HTML tag delimiters, with
restrictions based on the target type.
Target type | Server script HTML tag delimiters | Restrictions |
---|---|---|
Web Target | <% … %> | Available to Web site targets only |
PowerDynamo | <!–SCRIPT –> | |
Active Server Pages | You have four choices for script delimiters: <% … %>, <%! … %>, <%= … %>, and <SCRIPT RUNAT=SERVER> </SCRIPT> |
|
JSP | You have three choices for script delimiters: <% … %>, <%! … %>, and <%= … %> |
Available to JSP targets only |
When you add a Web target server script, the Script editor
inserts <% … %> script tag
delimiters in the source for your Web page. If necessary, these
tags are converted by the deployment controller to the correct syntax
for the platform where you deploy your Web site.
To embed a server script on a Web page:
-
With a Web page open in the HTML editor,
right-click in the integrated Script editor. -
Select New Script>Server>target
server type from the pop-up menu, then select the type
of delimiter you want if a choice is available.The server script delimiters you select appear in the Source
view for your Web page. A new server script icon appears in the
Page view, which you can position on the page, and a server script
item appears (as the current item) in the first drop-down list of
the integrated Script editor.
Importing script files
To import text
from a server script file in a Web site target, you can use the PSIMPORT
tag and its SRC attribute to indicate the name of the file you are importing:
1 |
<PSIMPORT SRC="script-file.PSS"> |
You can drag and drop the PSIMPORT tag and its SRC attribute
from the System Tree to the Source view of the current page in your
Web target.
The PSIMPORT tag supports deployment to PowerDynamo and ASP.
During deployment the PSIMPORT tag is converted to a server-side
include tag that is appropriate for the target application server
platform. For example, if you deploy to ASP, the Web target deployment
controller for ASP converts each PSIMPORT tag to an ASP server-side
include (<!–#include –>).
File extension for multiplatform deployment To ensure that the imported scripts are processed correctly
for each platform, you need to specify a PSS extension for each
script file you import.
Including HTML files
You can also have the application server include text from
a file that contains HTML only. To include an HTML file in a Web
site target, you can use the PSINCLUDE tag and its SRC attribute
to indicate the name of the file you are including:
1 |
<PSINCLUDE SRC="html-file.HTM"> |
The PSINCLUDE tag supports deployment to ASP and PowerDynamo. During
deployment, the PSINCLUDE tag is converted to a server-side include tag
that is appropriate for the target application server platform.
For example, if you deploy to ASP, the Web target deployment controller
for ASP converts each PSINCLUDE tag to a server-side include (<!–#include–>).
Files included by using PSINCLUDE must contain HTML only — not
scripts
. If several files need to include common text
from a single file, you need to ensure that the included text makes
sense in all of the files in which it is included. For example,
if the included text contains links to other files, you need to
make sure that the paths specified for the links work in all contexts.
The PSIMPORT and PSINCLUDE tags are not supported in JSP targets.
Using existing ASP pages
If you have an existing
ASP page that you want
to use in your Web target, and that page includes server code written
in VBScript, you must add the following line at the very top of
the file:
1 |
<%@ LANGUAGE=VBScript %> |
Make sure you do this before opening the file in the HTML
editor or importing the file into a Web target.