[top]
[prev]
[next]

Road Map
Glossary
Table of Contents
Index
Documentation Top
Global Index
|
Database Servlets
The JBMSTours application includes two (related) servlets. A servlet is a "server-side" Java application that runs embedded in a Web server. Servlets can start up and access Cloudscape as an embedded Java application.
If you have one of the following Web servers, you can run the servlets:
- Cloudconnector
- Java Web Server 1.1
This lesson is a quick-start on running the example servlets.
Refer to your Web server or application server documentation for detailed information on how to configure and enable servlets. The basic idea is that once you register the servlets correctly, you should be able to access them and see what they do.
There are also several books available on how to create servlets.
About the Servlets
The JBMSTours application includes the following classes:
- JBMSTours.servlets.OpeningServlet
A servlet that generates an HTML page with a form that allows users to choose a city and a range of dates. When users click submit, it submits the information to GetHotelsForCity.
- JBMSTours.servlets.GetHotelsForCity
A servlet that receives input parameters from OpeningServlet and that displays hotels and availability information for a given city and range of dates.
- JBMSTours.servlets.HTMLUtil
A utility class that supports the HTML generation of the servlets.
Appropriate Web Servers and Web Browsers
If you have purchased and installed Cloudconnector, use that as your Web server. Otherwise, you can use Java Web Server (version 1.1).
You can use any Web browser that supports JavaScript.
Running the Servlets
Configure Cloudconnector for the Servlets and Start Cloudconnector
NOTE: These instructions assume that you are familiar with how to start Cloudconnector from the command line. For a good introduction to how to start Cloudconnector, see the instructions for running Cloudscape's simple demo. You will need to restart Cloudconnector in this example.
- Open a command window.
- Change directories to your weblogic.system.home directory, the directory in which you keep the CloudscapeServer folder and the weblogic.properties file. The default location for these is %CLOUDSCAPE_INSTALL%/frameworks/cloudconnect.
- In this window, set the class path to include:
- Use a Cloudscape utility that tests your class path for a particular environment. You will use it with the arguments CloudconnectorServer, to test for a Cloudconnector server environment, and sampleApp, to test for the sample application libraries.
java COM.cloudscape.tools.sysinfo -cp CloudconnectorServer sampleApp
The utility displays a message indicating success or failure. If you got a failure message, check your class path carefully.
- Edit the weblogic.properties file that resides the current directory. Make the changes described in the following step.
- Register the servlets provided with this example by adding the following lines to the file at the end of the section called "USER-WRITTEN AND DEMO SERVLET REGISTRATIONS."
weblogic.httpd.register.OpeningServlet=\ JBMSTours.servlets.OpeningServlet
weblogic.httpd.register.GetHotelsForCity=\ JBMSTours.servlets.GetHotelsForCity
- Save the file.
- Start Cloudconnector from the directory that contains the weblogic.properties file that you just edited. When starting Cloudconnector, being sure to set the value of cloudscape.system.home to the location of the directory that contains toursDB:. If you're doing just this lesson, use the pre-built database; simply set the value of cloudscape.system.home to %cloudscape_install%/demo/databases. Start Cloudconnector like this:
java -ms16m -mx32m -Dcloudscape.system.home= your_tutorial_system COM.cloudscape.core.CloudscapeServer - Start a browser from the same machine or any machine on the network.
- Open the following location:
http://<serverName>:<portNumber>/OpeningServlet
replacing <serverName> and <portNumber> with the correct server name and port number. Most likely, these will be localhost and 7001.
Skip ahead to Use the Servlets.
Configure Java Web Server 1.1 for the Servlet and Start Java Web Server
NOTE: These instructions assume that you are familiar with how to start Java Web Server and how to include libraries in its class path. You will need to restart Java Web Server in this example.
- Before starting the Java Web Server, add the main Cloudscape library to its class path (cloudscape.jar or cloudsync.jar). You can do that by setting the class path in the command window from which you start the server.
- Copy the entire toursDB directory into the outermost directory for the Java Web Server. (You have to copy the database into the Web server's working directory because there is not a reliable way of setting a system property for the servlet, at least as of Java Web Server 1.1. For that reason, the servlet always thinks of its working directory as the cloudscape.system.home directory.)
- Start the Web server.
c:\JavaWebServer1.1\bin\httpd - Register the servlets like this:
- Start the Administration Tool by clicking on the appropriate link from the main page for the Web server (http://localhost:8080).
- Select Web server, and click Manage.
- Click the Servlets icon.
- Click Add under the servlets hierarchy.
- Register OpeningServlet. Specify OpeningServlet as the servlet name, and JBMSTours.servlets.OpeningServlet as the servlet class as shown below.
- Click Add.
- Provide a description.
- Click the "no" button next to Load at Startup.
- Click Save.
- Click Add under the servlets hierarchy.
- Now configure GetHotelsForCity. Specify GetHotelsForCity as the servlet name, and JBMSTours.servlets.GetHotelsForCity as the servlet class.
- Click Add.
- Provide a description.
- Click the "no" button next to Load at Startup.
- Click Save.
- From a browser (same machine or another one on the network), open the following document:
http://<serverName>:<portNumber>/servlet/OpeningServlet
replacing <serverName> and <portNumber> with the correct server name and port number. Most likely, these will be localhost and 8080.
- Do all the steps outlined in Use the Servlets.
Use the Servlets
Once the HTML page is loaded, it provides a window that allows you select a city and a range of dates.
- If you wish, examine the source code for
JBMSTours.servlets.OpeningServlet.java in /demo/programs/tours/JBMSTours/servlets. The servlet queries the database and dynamically generates the HTML.
- Choose a city, and select a range of dates, then click Submit Query.
OpeningServlet sends the parameters you have selected to GetHotelsForCity.
- If you wish, examine the source code for
JBMSTours.servlets.GetHotelsForCity.java in /demo/programs/tours/JBMSTours/servlets. The servlet queries the database and dynamically generates the HTML.
The first time you access the servlet, the servlet attempts to boot Cloudscape if it is not already booted. It then attempts to connect to toursDB. (toursDB must be in the cloudscape.system.home directory).
- Close the Web browser.
- Stop the server if appropriate.
|