Caché Server Pages (CSP) technology allows you to build and deploy high-performance, highly-scalable Web applications. CSP lets you dynamically generate Web pages, typically using data from a Caché database. These pages are dynamic; that is, the same page may deliver different content each time it is requested.
-
Display inventory data that changes minute by minute.
-
Support Web communities with thousands of active users.
-
Personalize pages based on user information stored in the Caché database.
-
Customize pages based on the user data to different users, depending on their requirements and their security permissions.
-
Serve up HTML, XML, images, or other binary or textual data.
-
Deliver fast performance, because it is tightly coupled to the high-performance Caché database.
CSP is well-suited for database applications. In addition to providing rapid access to the built-in Caché database, it provides a number of features essential for Web-based database applications including
-
-
-
The ability to perform interactive database operations from in a Web page.
CSP supports two styles of Web development.
-
For those who wish to develop applications
programmatically, CSP provides an object framework for creating dynamic Web pages using classes.
-
For those who prefer to develop applications using
HTML files, CSP provides an HTML-based markup language that allows the inclusion of objects and server-side scripts within Web pages. You can combine these two techniques within an application for maximum flexibility.
Caché Server Page requests are processed using a standard Web server (all the leading servers are supported) and the standard HTTP protocol. CSP manages communications between the Web server and Caché and invokes application code to generate the page. The request and return process is as follows:
-
An HTTP client, typically a Web browser, requests a page from a Web server using HTTP.
-
The Web server recognizes this as a CSP request and forwards it to Caché using a fast server API.
-
The CSP Server running in Caché processes the request and returns a page to the Web server.
-
The Web server sends it to the browser for display.
The Web Server and the Caché server are abstract components, which may be implemented by one or many computers. During development, all three components may be on a single PC. In a large scale deployment, there may be multiple Web and Caché servers in two- or three-tier configurations.
To keep this guide simple, it treats these components as though there were one of each. It also describes CSP as though it was only serving HTML pages, although almost everything applies directly to XML and other text formats and most things apply to binary formats such as images.
To be productive with CSP you should have some familiarity with the following:
-
Caché Objects and Caché ObjectScript
-
-
-
Some useful resources for learning HTML and JavaScript include:
Caché comes with a set of sample CSP pages. To view these:
-
-
Make sure that the local Web server on your machine (such as IIS or Apache) is running.
-
Start your browser and go to this page:
Where 8972 is your Caché server port number.
-
If you have activated any of the advanced security features in Caché, a login page might display. Log in.
-
Caché displays a list of sample CSP pages along with a short description of each. Click on any that interest you.
CSP Tutorials and Online Documentation
To set up the CSP Gateway, see
There are three online tutorials to help you learn to create CSP pages:
The following online documentation is also available, including this book:
-
-
-
Web Gateway documentation, available on the System Management Portal at
[Configuration > CSP Gateway Management > Help].
Class reference information for these classes:
Creating Your First CSP Application
No introduction to a development technology is complete without the ubiquitous
Hello, World example. This section includes a demonstration of how to create a
Hello, World CSP page in two different ways.
-
Programming a class-based CSP page; creating Web page objects.
-
Using a marked-up HTML file.
Creating a Class-based CSP Page
Create a CSP page by creating a subclass of
%CSP.Page
and overriding its
OnPage method. Any output written to the principal device by this method is automatically sent to a Web browser and displayed as a Web page.
To create a
Hello, World page programmatically, do the following:
-
-
Create a new project in the local database USER namespace by selecting
File > New Project.
-
-
On the first page of the Wizard, specify
Test for the package name and
Hello for a class name
-
On the second page, select
CSP as the class type.
-
Click
Finish. You see the new CSP class definition in the Studio Class Editor:
Class Test.Hello Extends %CSP.Page [ ProcedureBlock ]
{
ClassMethod OnPage() As %Status
{
&html<<html>
<head>
</head>
<body>>
;To do...
&html<</body>
</html>>
Quit $$$OK
}
}
-
In the
OnPage method, replace the comment:
Write "<b>Hello, World</b>",!
-
Save and compile the new class using
.
-
This application works as follows:
-
The browser sends a request for
Test.Hello.cls to the local Web Server
-
The Web Server passes this request to the CSP Gateway (connected to the Web Server) which, in turn, passes the request to a Caché CSP Server. In our case the browser, the Web server, and the Caché Application server are all running on the same machine. In a real deployment, these would probably be on separate machines.
-
The Caché CSP Server looks for a class called
Test.Hello and invokes its
OnPage method (which we edited in Caché Studio).
-
Any output that the
OnPage method writes to the principal device (using the Write command) is sent back to the browser (via the CSP Gateway and the Web Server).
These steps are at the heart of CSP: The rest of CSP's functionality is built on top of this behavior.
If you like, you can make your example application more interesting by adding more code. For example, insert the following lines after the line containing
Hello, World:
Write "<ul>",!
For i = 1:1:10 {
Write "<LI> This is item ", i,!
}
Write "</ul>",!
Now your page contains an unordered (bulleted) list of 10 items. Note that, in this context, Caché uses the exclamation point (!) character to write a carriage return to the principal device.
Creating an HTML Tag-Based CSP Page
Another way to create a CSP page is to create an HTML file and let the CSP compiler transform it into a CSP class.
To create a
Hello,World page using an HTML file, do the following:
-
Start Caché Studio and select
.
-
Edit the new CSP file in the Studio CSP Editor (which offers CSP and HTML syntax coloring) and add the following:
<html>
<body>
<b>Hello, World!</b>
</body>
</html>
-
-
As with the previous example, you see
Hello, World displayed in the browser.
Note:
You can also create an HTML file using a text editor or HTML editor. Save this file as
Hello.csp in the local directory
/cachesys/csp/user (where
cachesys is where you have installed Caché).
This application works as follows:
-
The browser sends a request for
Hello.csp to the local Web Server
-
The Web Server passes this request to the CSP Gateway (connected to the Web Server) which, in turn, passes the request to a Caché CSP Server.
-
The Caché CSP Server looks for the file
Hello.csp, and hands it to the CSP compiler.
-
The CSP compiler creates a new class called
csp.Hello with an
OnPage method that writes out the contents of the
Hello.csp file. (It actually generates a set of methods each of which are, in turn, called from the
OnPage method). This compilation step only occurs when the
.csp file is newer than the generated class; subsequent requests are sent directly to the generated class.
-
The CSP Server now invokes the newly generated
OnPage method and its output is sent to the browser as in the previous example.
As with the case of programmatic development, this is a purposefully oversimplified example included for pedagogical reasons. The CSP compiler is actually a specialized XML/HTML processing engine that can:
-
Process server-side scripts and expressions in an HTML page
-
Perform server-side actions when certain HTML tags are recognized.
As with the programmatic example, you can make this page more interesting by adding programming logic. For example:
<html>
<body>
<b>Hello, World!</b>
<script language="CACHE" runat="server">
// this code is executed on the server
Write "<ul>",!
For i = 1:1:10 {
Write "<li> This is item ", i,!
}
Write "</ul>",!
</script>
</body>
</html>
As with the programmatic example, the resulting page displays an unordered (bulleted) list of 10 items.