Embedded Server Pages
See Also
The ESP Standard Environment
Each HTTP request to an
ESP web page causes a standard environment to be created that
represents the state of the request, the server, form data, uploaded
files and any client session state. ESP automatically creates this
environment so that many web tasks can be accomplished without
programming.The ESP Standard Environment pre-defines a set of request global variables and functions. These are variables are private to the request, but global in scope so that all functions and classes can access their data within an ESP page without any C or C++ required coding.
See the Embedded Server Pages JavaScript API Reference for full ESP / EJS API documentation.
JavaScript Variables
The ESP run-time defines the following JavaScript variables for use inside an ESP page.| Variable Name |
Description |
| application [] |
Stores user defined application data and is
shared across all requests |
| cookies [] | Request cookies supplied by the client with the
request |
| false |
False boolean value |
| files [] |
Uploaded files supplied by the client with the
request |
| form [] |
Client form data. Includes both query string and posted data |
| global |
Global variables for this request |
| headers [] |
HTTP request headers |
| Infinity |
Floating point number set to Infinity |
| local |
Local variables for the outermost JavaScript block in the ESP web page |
| Nan |
Floating point number set to "Not a
Number" |
| null |
Defined variable set to Null |
| request [] |
Request details |
| server [] |
Server details |
| session [] |
Session state data for the current client. May
be shared across multiple requests for a given
client |
| true |
True boolean value |
| undefined |
Variable has no value and is set to the
Undefined Value |
JavaScript Functions
ESP defines the following global functions for use inside an ESP page.| Script Name |
Syntax |
Examples |
Description |
| Array |
Array(elt1, elt2, ...) Array(size) |
var o = new Array("item 1", "item 2"); var o = new Array(256); |
Create an array and insert elements. The second form creates an array with elements named "0", "1", "2", and so forth up to the nominated size. |
| assert |
assert(condition) |
||
| createSession |
createSession(timeout); | createSession(1800); |
Create session state for this client. No effect
if a session has aleady been created. This creates a session
cookie that is sent to the client in the response. The timeout
is in seconds. |
| destroySession |
destroySession() |
destroy(Session); |
Terminate the current session. |
| eval |
eval(script); |
eval("var " + x + " = " + string); | Evaluate the given script. |
| exit |
exit(status) |
exit(0); |
Immediately terminate the current script or
ESP. |
| include |
include(filename); |
include("myLib.js"); |
Server side inclusion of a JavaScript library.
The nominated file is read and parsed inline when the page is
compiled by AppWeb. |
| Object |
Object(); |
var o = new Object(); |
Create a new object. |
| print |
print(string, ...); |
print("Hello World\n"); | Print the given strings to the web server standard output. |
| println |
print(string, ...); |
print("Hello World"); | Print the given strings to the web server standard output followed by a new line. |
| printVars |
print(v, ...); |
print(obj1, obj2, obj3); |
Print the string representation of the given
objects to the web server standard output. Objects are expanded
and all properties are printed. Great for debugging. |
| redirect |
redirect(url, [code]); |
redirect("notFound.html", 302); redirect("pageTwo.esp"); |
Redirect the client's browser to a new
page. |
| refCount |
refCount(o); |
var count = refCount(obj); |
Return the number of references to this
object. |
| setHeader |
setHeader("myHeader: true"); |
Set a HTTP header in the ESP response to the
client. |
|
| trace |
trace(message); trace(level, message); |
trace(2, "Message at level 2"); |
Write a message to the AppWeb log. |
| useSession |
useSession(timeout); |
useSession(1800); |
This is an alias for createSession. |
| write |
write(args, ...); |
write("Hello World"); write("<h1>Today is ", date); |
Write the given arguments back to the client (browser) in the place of the ESP script. Multiple calls to write and its derivatives may be used. |