!--NewPage-->

    All Examples

# package examples.applets

##

- PhoneBook1

# about this package

This package demonstrates how to deploy applets in the WebLogic Server, and how to use WebLogic JDBC from a remote client (the applet).

# how to use this package

## The PhoneBook1 applet

PhoneBook1 is an applet that accesses a small database containing names and addresses via WebLogic JDBC. The applet lists out the entries from the CUSTOMER table and allows you to select each entry, displaying it's details in separate fields.

Note, because of Java's security model, you can't use a regular two-tier JDBC driver in an applet, so we're using WebLogic JDBC to connect to a pool driver on the WebLogic Server. You can configure the pool driver to use an accompanying two-tier driver suited for your database, such as WebLogic jDriver for Oracle, WebLogic jDriver for Microsoft SQL Server, or WebLogic jDriver for Informix. Using the pool driver allows you to configure the database and the driver without affecting the applet code, since your applet code only sees a the connection to the pool, which does not change.

A Cloudscape database is already set up for this example. The applet uses a connection pool called 'demoPool', which connects to the Cloudscape database. You must uncomment the configuration properties for 'demoPool' in your weblogic.properties file.

If you want to use a different RDBMS other that Cloudscape, you'll need to create a database table named CUSTOMER with the fields CUSTID, NAME, ADDRESS, CITY, STATE, ZIP, AREA, and PHONE. Then, you'll need to re-configure the 'demoPool' connection pool for your databse.

This applet will not work if you are running the server using JDK 1.2 or later since the web-browser is running an incompatible 1.1 JVM. If you wish to deploy applets from a server running with JDK 1.2, we suggest you use the Java Plug-in.

### Building the applet

To compile the applet, you must first set up your environment, as described in the 'Getting Started' guide under Setting your development environment. Once you have set up a development shell, change to the examples/applets directory and compile the applet with the following:

      javac -d %SERVER_CLASSES% PhoneBook1.java

This command compiles and places the PhoneBook1.class under the directory pointed to by the environment variable SERVER_CLASSES, which is set up in your environment by the setEnv.cmd script.

You must add the SERVER_CLASSES directory to your weblogic.class.path property on the command line when you start the server so that it is accessible by the WebLogic Server. The WebLogic Server will deploy this applet class to a web-browser upon request via the ClasspathServlet.

You must also register the ClasspathServlet against the virtual servlet name classes. The CODEBASE in the applet tag is set to "/classes/", matching the virtual servlet name of the ClasspathServlet. When the HTML page containing the applet is received by the web-browser, the browser requests the applet classes from the URL specified by the CODEBASE.

### Deploying the applet

An applet must be embedded in an HTML page that is accessible from an HTTP server (such as the WebLogic Server). You can rely on the browser's own JVM implementation, or you can use the Java Plugin. There are a number of HTML files in this directory that deploy the PhoneBook1 applet, described in the table below. You must copy each of these to the document root of your server. The document root directory is where the WebLogic Server searches for public HTML files. By default it is set to the /myserver/public_html directory in your WebLogic installation directory.

The following table lists the HTML or JSP files provided with this example, that can be used to deploy the applet. Against each file is a description of how the applet is run within the browser from this file.

Note that the last four pages illustrate how to deploy the applet using the Java Plugin. Two examples are provided for both the HTML and JSP approaches to demonstrate how to use either the 1.1.3 Java Plugin or the 1.2 Java Plugin. These versions of the Java Plugin use different releases of the JRE. If your applet communicates with the WebLogic Server, it must be compiled with and run within a compatible JVM.

- If your WebLogic Server is running under Java 1.2, then your applet must be deployed using the 1.2 Java Plugin.
- If your WebLogic Server is running under Java 1.1, then your applet must be deployed using either the 1.1.3 Java Plugin, or the web browser's own JVM.

HTML page | How the applet is deployed
--- | ---
phonebook1.html | Uses the standard HTML <APPLET> tags to deploy the applet. The applet is run in the browser's JVM and hence must be compiled under JDK1.1 and must communicate with a WebLogic Server running under Java 1.1
plugin113.html | Uses a combination of the <OBJECT> and <EMBED> browser tags to embed the applet in the Java Plugin version 1.1.3. This causes the browser to download the plugin (once only) and run the applet in a standard Java 1.1 VM from Sun. The applet should be compiled using a 1.1 JDK (JDK 1.1.7B) and the WebLogic Server it communicates with must also be running under Java 1.1
plugin12.html | Uses a combination of the <OBJECT> and <EMBED> browser tags to embed the applet in the Java Plugin version 1.2. This causes the browser to download the plugin (once only) and run the applet in a standard Java 1.2 VM from Sun. The applet should be compiled using a 1.2 JDK (JDK 1.2.1) and the WebLogic Server it communicates with must also be running under Java 1.2
phonebook1.jsp | Uses the <jsp:plugin> tags to embed the Java 1.1.3 Plugin into the HTML response page. The generated JSP servlet automatically detects the browser type and sends only the appropriate plugin syntax. It is also easier to maintain.
phonebook2.jsp | Uses the <jsp:plugin> tags to embed the Java 1.2 Plugin into the HTML response page. The generated JSP servlet automatically detects the browser type and sends only the appropriate plugin syntax. It is also easier to maintain.

Copy each of these files to the document root of the WebLogic Server. You'll need to set up JSP to use the JSP pages.

Start the WebLogic Server in another command shell.

Open a web browser that supports applets. Make sure that the environment you start the web browser in does not have any classes set in the System CLASSPATH; otherwise, it will not download the classes via the server, but will get them from the local machine, and you may experience problems. In the web browser or with the JDK appletviewer, request the URL:

      http://localhost:7001/phonebook1.html

The applet should load, connect to the WebLogic Server via JDBC, download the entries from the database, and allow you to view the details of each entry by selecting a name from the list at the top of the applet.

### Notes

The applet contains two lines of commented-out code that use a class called WebLogicPreLoader, that is provided in this directory. You can use this class to ensure that all of the necessary classes required by WebLogic JDBC are downloaded by a separate thread. In an applets that makes interactive calls via JDBC, the operation will be smooth since the required classes will have already been downloaded on the client side. This example does not make interactive JDBC calls (it pulls all of the information down at initialization) - so it would not benefit from using the WebLogicPreLoader, but it is included in the example to demonstrate how it may be used. To use the WebLogicPreLoader, compile it similarly to the applet, placing it in the SERVER_CLASSES directory.

You can learn more about WebLogic JDBC connections in the technical support document, What do I do with all these connections, anyway?

# trouble shooting . . .

You may find the following online documents useful for trouble shooting your applets:

- Testing connections
- Troubleshooting CLASSPATH
- Troubleshooting Applet Security problems
- Troubleshooting CODEBASE

# there's more . . .

For information on using applets with WebLogic, see Using applets with WebLogic.

The Applet Archiver is a tool for archiving all the classes that your applet uses. It is useful for generating jar and cab archive files to improve the download time of your applets.

For more information about the APIs used in this example, read the Developers Guides for WebLogic JDBC and dbKona.