Chapter 7 Developing Applications with PowerJ and EAServer


Building Web applications with PowerDynamo and Java

Application servers

There are many ways to put together a Web application. A key element in a Web application is an application server for building dynamic Web content from database data. In EAServer, PowerDynamo performs this function.

How PowerDynamo works

You create PowerDynamo templates in which you specify tags or scripts that execute a database query and format the retrieved data as an HTML page. This processing is done on the server, and the resulting page is sent back to the Web browser client.

PowerDynamo works with other EAServer tools. You can use Java applets and servlets in your PowerDynamo Web application. You can use PowerJ or PowerSite to develop and debug scripts in PowerDynamo templates.

The network architecture might look like this:


You can use either PowerSite or Sybase Central as the interface for your PowerDynamo development.

Types of PowerDynamo applications

Basic HTML forms The simplest PowerDynamo application does not involve Java. The HTML page has an HTML form that collects query criteria from the user. The browser sends the query criteria to a PowerDynamo template to retrieve dynamic content. No validation occurs in the browser. PowerDynamo processes the query and returns an HTML page with the requested data.

JavaScript processing for forms You can validate data collected in a form with JavaScript. The scripts in the HTML page implement the business rules needed for validating the data.

Applet for form validation Instead of an HTML form, the Web page includes an applet in which the user enters information. The applet validates the input and uses it to build a URL that is sent to PowerDynamo to retrieve dynamic content. By encapsulating the processing in an applet, you may be able to reuse it in other pages.

Accessing Java classes A PowerDynamo script can access Java classes stored in the PowerDynamo Web site or in the file system. To access a Java class from DynaScript, call the java.CreateObject method.

General procedure

The following general procedure gives you an idea of how to develop a PowerDynamo Web application that involves Java. The application uses an applet to validate user input and PowerDynamo to retrieve and display data.

In Sybase Central:

  1. Create a PowerDynamo Web site in the folder where you published the PowerJ WebApplication target.
  2. Create a template that includes a SQL query to retrieve data from a database. The query uses the data collected by the applet:
    <!--SQL SELECT ...
    WHERE ( salesorder.order_date BETWEEN '$startdate '
    AND '$enddate '  ) 
    -->

    The template has an HTML table with PowerDynamo formatting instructions that specify how the data will be formatted as HTML:
    <TABLE BORDER>
    <TR><TH>First name</TH> 
    <TH>Last name</TH> 
    <TH>Number of orders</TH></TR><!--formatting--><TR><TD><!--data--></TD>
    <TD><!--data--></TD>
    <TD><!--data--></TD>
    </TR><!--/formatting-->
    </TABLE>

In PowerJ:

  1. Create a Java applet target and code the applet.
    The applet displays a form, then builds a URL that includes the user-entered data:

    http://www.myhost.com/.../ObtainOrders.stm?
    startdate=1999-1-10&enddate=1999-3-11


    The code calls the showDocument method of AppletContext to have the browser request the PowerDynamo template ObtainOrders.stm using this URL.
  2. Create a WebApplication target with the applet as a dependent target.
  3. Edit the HTML page in the WebApplication target to display the applet.
  4. Deploy the WebApplication to the PowerDynamo Web site.

After a user has entered dates in the applet and clicked to show results, the applet instructs the browser to request the template URL. The PowerDynamo-enabled Web server forwards the request to PowerDynamo. PowerDynamo queries the database and formats the results in an HTML table. The Web server sends the resulting page to the user's browser.

This scenario is described in detail in PowerJ Getting Started.

 


Copyright © 2000 Sybase, Inc. All rights reserved.