What are J9 Server Pages?
J9 Server Pages (J9SP) are web pages using
HTML and special server side script tags that enable you to create dynamic content and run server side scripts to manipulate automation devices. J9 Server Pages (J9SP) can be identified by their file
.j9sp file extension.
Dynamic content is web page content that is customized for each visitor on the fly, based upon their actions or requests. For example visitors to your site could be shown the
Weather Driver's current temperature and allow you to change the thermostat settings within your home.
What do I need to use J9 Server Pages?
- or -
- Microsoft Internet Information Server (IIS) 5.0+
J9SP File Syntax
J9SP files are similar to
Active Server Page (ASP) files and
Java Server Page files but use the
J9 Scripting Language.
They have the same format as an
HTML file (with
HTML tags) and can also contain server scripts, surrounded by the delimiters
<% and
%>. Server scripts are executed on the server, and can contain any valid
J9 Scripting Language expressions, statements, functions, or operators.
J9SP File Extension
J9SP files must have a file extension of
.j9sp.
Example: HelloWorld.j9sp
Outputing Content to a Browser
The built-in
Response Object contains a
Write method that outputs data to the browser (or more specifically, renders the data inline into the HTTP output stream.).
Here is a simple Hello World! example:
<html>
<body>
<%
Response.Write("Hello World!");
%>
</body>
</html>
Shorthand Syntax:There is also a shorthand syntax for the Response.Write method. The following example outputs the same content as the example above, but uses the shorthand output syntax
<%= ... %>.
<html>
<body>
<%= "Hello World!" %>
</body>
</html>
J9SP Web Page Examples
Simple page to display the weather device's temperature
This example requires that the
Weather Driver be configured as a device with an instance name of
weather.
<html>
<body>
Current Temperature: <%= weather.Temperature %>
</body>
</html>
Display all of the Elk M1 device's Output values
This example requires that the
Elk M1 Driver be configured as a device with an instance name of
elkm1.
<html>
<body>
<%
// Get a reference to the outputs
outputs = elkm1.OutputStates;
// Loop through each output
for (i=0; i < outputs.count; i++)
{
Response.Write( "Output # " + i + " : " + outputs[i] + "<br>");
}
%>
</body>
</html>
This example is the same as the previous but uses the shorthand output syntax:
<html>
<body>
<%
// Get a reference to the outputs
outputs = elkm1.OutputStates;
// Loop through each output
for (i=0; i<outputs.count; i++)
{ %>
Output # <%= i %> : <%= outputs[i] %><br>
<%
}
%>
</body>
</html>
Activate an Elk M1 task from a button press on a web page
This example requires that the
Elk M1 Driver be configured as a device with an instance name of
elkm1.
The built in
Response Object contains a
Form property that contains form information including the press of the button named "task1".
<%
confirmationMessage = ""; // initialize confirmation message
// Check if the "task1" button was pressed.
if ( Request.Form.Contains("task1") )
{
elkm1.ActivateTask(1);
confirmationMessage = "Task 1 was activated.";
}
%>
<html>
<body>
<%= confirmationMessage %> <br>
<form method="post">
To active task 1, click the button: <input type="submit" name="task1" value="Task 1" />
</form>
</body>
</html>
See Also