📄 ejscript.htm
字号:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<META NAME="Generator" CONTENT="Microsoft Word 97">
<TITLE>JavaScript -- GoAhead WebServer </TITLE>
<META NAME="Template" CONTENT="C:\Program Files\MSOffice\Office\html.dot">
<LINK rel="stylesheet" href="../../style/normal.htm" type="text/css"></HEAD>
<BODY LINK="#0000ff" VLINK="#800080">
<H1>JavaScript</H1>
<P>GoAhead developed an embedded version of JavaScript called Ejscript™. As JavaScript 1.2 is now quite a large language, its size prohibits its use in most embedded devices. GoAhead's embedded JavaScript is designed to solve this delima. Ejscript™ is a strict subset of JavaScript and implements the essential elements of the language. Ejscript also interfaces to Active Server Pages (ASP) to allow the easy creation of dynamic web pages. </P>
<P>When JavaScript is used inside an ASP web page it consists of a script within ASP delimiters. The basic format is: </P>
<PRE>
<% function(arguments, ...); %></PRE>
<P>JavaScript functions are created by the <A HREF="../ej/ejSetGlobalFunction.htm">ejSetGlobalFunction</A>. When the function is evaluated, the corresponding C procedure that implements the JavaScript function is called. </P>
<P>Ejscript implements the following JavaScript elements ( complete <A HREF="../ej/EjSpec.htm">specification</A> ): </P>
<UL>
<LI>Case sensitivity </LI>
<LI>Whitespace </LI>
<LI>Semicolons </LI>
<LI>Comments </LI>
<LI>Identifers </LI>
<LI>Data types including numbers, booleans, strings with backslash characters </LI>
<LI>Full expressions </LI>
<LI>If/else, for, return </LI>
<LI>Global function calls </LI></UL>
<P>The following language elements are not implemented. </P>
<UL>
<LI>Arrays </LI>
<LI>Objects </LI>
<LI>Labeled statements </LI>
<LI>Control flow statements including: break, case, continue, default, do/while, export, for/in, function, import, switch, var, while, with </LI>
<LI>Regular expressions </LI></UL>
<P>JavaScript scripts can span multiple lines by using a "\" as the last character on the preceding line. When used in ASP pages, function arguments can contain any query variable defined in the URL query string or defined in either the <A HREF="websVar.htm">standard variable set</A>. URL query strings are automatically decoded and JavaScript variables are defined to the decoded query value. For example, to parse the name and address encoded as a query string in a URL, use the following code: </P>
<PRE>
<A HREF="http://localhost/mypage?name=smith&age=35">http://localhost/mypage?name=smith&age=35</A>
int myAspProcedure(webs_t wp, int argc, char_t **argv) {
	char_t *name = websGetVar(wp, "name", "undefined");
	char_t *age = websGetVar(wp, "age", "undefined");
websWrite(wp, "Name %s, Age", args);
}</PRE>
<P>JavaScript procedures are registered by using the <A HREF="websAspDefine.htm">websAspDefine</A> API. This publishes a C procedure as a JavaScript global function. For example:</P>
<PRE>extern int outputMyTable(int ejid, webs_t wp, int argc, char_t **argv);
websAspDefine("outputTable", outputMyTable);</PRE>
<P>The websAspDefine call publishes the JavaScript command "outputTable" and links it to the outputMyTable C procedure. When an ASP page is requested by the user's browser, any ASP JavaScript which uses the <I>outputTable</I>command will cause the <I>outputMyTable</I> to be called with the relevant arguments.</P>
<P>GoAhead Ejscript is quite secure because it only grants access to only those C procedures for which you wish to provide access and you exploit the full power of C to implement control logic. Traditional scripting languages often expose security flaws because general purpose functions give unintended control over system or data functions. </P>
<H2>See Also</H2>
<P><A HREF="asp.htm">Active Server Pages</A>, <A HREF="goforms.htm">GoForms</A>™, <A HREF="websSecurityHandler.htm">websSecurityHandler</A>, <A HREF="websUrlHandlerDefine.htm">websUrlHandlerDefine</A> </P></BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -