All Examples  

package examples.applets

Class Index

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 jdbcKona/Oracle, jdbcKona/Sybase, jdbcKona/MSSQLServer, jdbcKona/MSSQLServer4, or jdbcKona/Informix4. 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 depoloy 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.

Copy the file phonebook1.html to your document root. 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.

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:

there's more . . .

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