Working with CSP Files
Using CSP files with InterSystems IRIS is not recommended.
When working with other InterSystems products, a CSP (Web Server Page) 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.
To create a simple CSP page with Studio, perform the following steps:
Start Studio and create a new Project.
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:
My Sample CSP Page.
Save the page with
. The Save As
dialog appears. Specify a directory location and project name, and 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 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.
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.
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
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 an InterSystems 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 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
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 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 routines generated from this class, by opening them with
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
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
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
Content Date/Time: 2019-02-16 22:40:03