Using Caché Studio
Working with CSP Files
A CSP (Caché Server Page) file is a text file containing HTML, XML, or CSP markup commands. This file is stored on a Caché server machine and is compiled, by the CSP Engine, into an executable class that can process HTTP events sent from a browser.
You can use Caché Studio to create and edit CSP files in the same way you would work with class definitions or routines. CSP files are displayed in the Studio syntax-coloring editor allowing you to quickly spot errors in HTML as well as in any embedded server-side scripts.
To create a simple CSP page with Caché Studio, perform the following steps:
Start Studio and create a new Project in the SAMPLES namespace.
Create a new CSP file (with
Studio creates a new CSP Editor window containing a new CSP file named Untitled.csp
Replace the contents of the editor window with:
My Sample CSP Page.
Save the page with
. The Save As
dialog appears. Within the dialog, double-click the CSP application /csp/samples
(this is the directory in which we are going to save this CSP page) and then enter Sample.csp
in the Filename
box. Select Save As
View the resulting Web page from a browser with
At this point, you should see a very simple Web page containing the words My Sample CSP Page
in your browser.
To make this example more interesting, we can add an SQL query to the page that executes when the page is requested:
Position the cursor in the CSP Editor window at the start of the blank line after My Sample CSP Page
. In the dialog that appears enter the following SQL query:
SELECT Name,SSN FROM Sample.Person ORDER BY Name
Save and recompile the page with
View the resulting Web page from a browser with
Now your CSP page displays a list of names and social security numbers in an HTML table.
To create a new CSP file, select
. This creates a new CSP file named Untitled.csp
When you save this file for the first time, you are asked for a file name. If this file is part of a CSP application, create a folder with an application name, in which to put your new file.
The file name, which must have a .csp
extension, is used for both saving a physical source file on the Caché server as well as in a URL requesting this page. The application name also determines the URL used to request the CSP page as well as other characteristics.
For more information on CSP files and applications, see the Caché Server Pages
Default.csp Template File
When you create a new CSP file in Studio, it opens a new CSP Editor window and copies into it the contents of a CSP template file. You can edit or replace this template file in order to customize how Studio creates new CSP files. This file is a text file called Default.csp
and is located in the same directory as the Studio executable file. For a default installation, this is the /cachesys/bin
You can edit a CSP file in the same way you would edit any other document in Caché Studio.
The Studio includes dialogs, a wizard, and templates to assist with editing CSP files. These dialogs are available under the
menu and are described in the table below.
|Insert Menu Option
||Inserts a <csp:CLASS> tag at the current cursor location.
||Inserts a <csp:LOOP> tag at the current cursor location.
||Inserts a <csp:WHILE> tag at the current cursor location.
||Inserts a Caché objects method (in a <SCRIPT> tag) at the current cursor location
||Inserts a <csp:OBJECT> tag at the current cursor location.
||Inserts a <csp:QUERY> tag at the current cursor location.
||Inserts an SQL query (in a <SCRIPT> tag) at the current cursor location.
Save a CSP file using the
. This sends the source of the CSP file back to the Caché server (which could be on a remote machine) and save it on the server's local file system in the appropriate directory (specified by the Caché server's CSP application settings). Studio automatically saves backup files for the five previous saves of a CSP file. For more information, see Save Automatically Backs Up Routines, Include, and CSP Files
Compile a CSP file using
. Compiling a CSP File is a multi-step process: first the CSP file is fed through the CSP engine and converted into a Caché class (derived from the %CSP.Page
class). Then this generated class is compiled into one or more routines that contain executable code.
Sometimes it is easier to debug or understand a CSP file by looking at the code generated for it. You can use Studio to view the class generated for a CSP file, as well as the routine(s) generated from this class by opening them with
Viewing the Results of a CSP File
You can view the results of a CSP file in a browser by using
. This launches your default browser with the URL for the current CSP page. You can also use this command when editing a %CSP.Page
You can modify the server address portion of the URL used to display a CSP page in a specific project. To do this, select
and edit the value of the WEB Server
Viewing Syntax-Colored Source for Any URL
As an aid to debugging Web applications, Caché Studio lets you request a Web page from a URL and display its HTML source in a syntax coloring window. This can help you spot errors in Web pages more easily than viewing the rendered HTML in a browser.
You can open a URL Viewer window using the
and entering a URL in the resulting dialog.
To try this with a CSP sample page, do the following:
At this point, you sees the HTML returned by the custom.csp
page displayed in a syntax-coloring window.
You can use the URL viewer to view syntax-colored source for any Web page on the internet.