Previous Table of Contents Next


Cartridges

Cartridges are applications that run on the server. The WRB invokes them on an as-requested basis. Each cartridge is a separate process that can be started and stopped independently as required. Furthermore, each cartridge process, called an instance, is usually run in multiples—you can have 20 PL/SQL cartridge instances running on different machines within the network, and ten instances of another cartridge, all managed by the WRB.

There are many advantages to this division of cartridge processes. The architecture lends itself well to load balancing and application partitioning. Most importantly, if one cartridge fails, the other cartridges are not affected. A cartridge, running as a separate instance, could experience complete failure, infinite loops, and so on, and not cause a problem to the other cartridges, even other instances of the same cartridge. This robustness of performance is a great feature.

The WAS comes bundled with several cartridges, including the following:

  PL/SQL
  Java
  C
  LiveHTML
  Oracle Worlds (VRML)
  Perl
  ODBC

Some of the most commonly used cartridge options are described in the following sections.

PL/SQL

If you’re an Oracle developer, I know what you’re thinking: “Enough with all this architecture nonsense—how do I get the data out of the database, and into a browser?” This is your section.

Oracle provides a number of stored procedures and functions to be used with PL/SQL when building Web applications.

Consider the PL/SQL procedure in Listing 27.2.

Listing 27.2. PL/SQL to create stored procedure MY_FIRST_PAGE.


CREATE OR REPLACE PROCEDURE my_first_page

IS

BEGIN

  htp.htmlOpen;

  htp.headOpen;

  htp.title(‘My First Page’);

  htp.headClose;

  htp.bodyHead;

  htp.header(‘1’,‘Welcome to my first page.’);

  htp.line;

  htp.p(‘This is the first page ‘ ||

    ‘I ever created using PL/SQL.’);

  htp.bodyClose;

  htp.htmlClose;

END;

/


Note:  
This procedure contains a number of calls to procedures in the Oracle provided package HTP, designed to support the creation of HTML files. This package comes with WAS, and is not a standard PL/SQL package.

If you execute this code in SQL*Plus, it will create a stored procedure called my_first_page. Next, you could start your Web browser, and, depending upon how the WAS is configured at your installation, you could enter a URL in the location such as the following:


     http://www.corbinian.com/demo/owa/my_first_page

This would instruct the Web server to execute the my_first_page procedure that will write this file, which isn’t stored anywhere, but is instead sent across the network to the browser, as shown in Listing 27.3.

Listing 27.3. MY_FIRST_PAGE output (html file).


<HTML>

<HEAD>

<TITLE>My First Page</TITLE>

</HEAD>

<BODY>

<H1>Welcome to my first page.</H1>

<HR>

This is the first page I ever created using PL/SQL.

</BODY>

</HTML>

This HTML will appear in the browser as shown in Figure 27.4.


Figure 27.4.  my_first_page, displayed in a browser.

As you can see, an understanding of HTML is required, since all output written to the file and sent to the client to be displayed in the browser must be an HTML file.

Oracle provides a set of packages that contains procedures and functions for use with the WAS. The packages used the most often are the HTP and HTF packages. The HTP package consists of procedures to print various HTML tags. The HTF package contains the same set of instructions, but as functions instead of procedures; the two exist so you can embed functions from HTF in the procedure calls to HTP. For example, consider this code:


htp.tableData(‘This cell in the table is not in bold print!’);

This uses the tableData procedure to print a cell in a table. But what if you wanted to wrap the text in the HTML bold tag? You could do this:


htp.tableData(htf.bold(‘This cell in the table is in bold print!’);

Of course, you could also have done this:


htp.tableData(‘<B>This cell in the table is in bold print!</B>’);

This code contains the actual HTML bold tag pair in the character string (‘<B>’), and it has the same effect as using the HTF packaged function call. For that matter, you could also just use the htp print procedure to do everything:


htp.p(‘<TD><B>This cell in the table is in bold print!</B></TD>’);

This example also prints the cell and makes the text bold, using a simple print procedure and the HTML tags spelled out. However, it can be difficult to read, especially when combined with several other print statements. On the other hand, some of the HTP procedures that have several parameters can be difficult to read, too, more so than the original HTML. I find that I use HTP procedures to write most of the code, with a few actual HTML tags once in a while as required.


Previous Table of Contents Next
Используются технологии uCoz