Working with CSP Files
Using CSP files with InterSystems IRIS® is not recommended.
When working with other InterSystems products, a CSP file is a text file containing HTML, XML, or CSP markup commands. This file is stored on an InterSystems 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 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.
Sample CSP Page
To create a simple CSP page with Studio, perform the following steps:
Start Studio and create a new Project.
Select File > New > CSP File tab > Server Page to create a new CSP page.
Studio creates a new CSP Editor window containing a new CSP file named Untitled.csp.
Replace the contents of the editor window with:
<HTML> <HEAD> <TITLE>Sample Page</TITLE> </HEAD> <BODY> My Sample CSP Page. </BODY> </HTML>
Save the page with File > Save. The Save As dialog appears. Specify a directory location and project name, and select Save As.
Compile the page with Build > Compile .
View the resulting Web page from a browser with View > Web Page.
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.
Select Insert > SQL Query.
In the dialog that appears enter the following SQL query:
SELECT Name,SSN FROM Sample.Person ORDER BY Name
Check Create HTML Table and select OK.
Save and recompile the page with Build > Compile.
View the resulting Web page from a browser with View > Web Page .
Now your CSP page displays a list of names and social security numbers in an HTML table.
Creating a New CSP File
To create a new CSP file, select File > New > CSP File tab > Server Page. 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 InterSystems 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.
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.
Editing a CSP File
You can edit a CSP file in the same way you would edit any other document in Studio.
Studio includes dialogs, a wizard, and templates to assist with editing CSP files. These dialogs are available under the Insert menu and are described in the table below.
|Class||Inserts a <csp:CLASS> tag at the current cursor location.|
|Loop||Inserts a <csp:LOOP> tag at the current cursor location.|
|While||Inserts a <csp:WHILE> tag at the current cursor location.|
|Method||Inserts an InterSystems objects method (in a <SCRIPT> tag) at the current cursor location|
|Object||Inserts a <csp:OBJECT> tag at the current cursor location.|
|Query||Inserts a <csp:QUERY> tag at the current cursor location.|
|SQL Query||Inserts an SQL query (in a <SCRIPT> tag) at the current cursor location.|
Saving a CSP File
Save a CSP file using the File > Save. This sends the source of the CSP file back to the InterSystems 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 InterSystems 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 Files.
Compiling a CSP File
Compile a CSP file using Build > Compile. Compiling a CSP File is a multi-step process: first the CSP file is fed through the CSP engine and converted into a class (derived from the %CSP.PageOpens in a new tab 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 routines generated from this class, by opening them with File > Open or View > Other.
Viewing the Results of a CSP File
You can view the results of a CSP file in a browser by using View > Web Page. This launches your default browser with the URL for the current CSP page. You can also use this command when editing a %CSP.PageOpens in a new tab class.
You can modify the server address portion of the URL used to display a CSP page in a specific project. To do this, select Project > Settings and edit the value of the WEB Server field.
Viewing Syntax-Colored Source for Any URL
As an aid to debugging Web applications, 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 File > Open URL and entering a URL in the resulting dialog. You can use the URL viewer to view syntax-colored source for any Web page on the Internet