Java Cookbook : Hotel Reservation using Servlets  Java Cookbook : Hotel Reservation using Servlets 


Table of Contents

Application Overview
Software Requirements
Terminology
Extracting the source code
Configuring the Application
Deploying and Running the Application
Sample Application Files

Application Overview

This sample demonstrates Java Servlets technology using the Hotel Reservation System. This sample models a typical three-tier application. A web browser acts as a client and invokes the servlet that executes in the middle-tier and uses facilities provided by the HotelJDBC class to perform database access to Oracle9i database, which is the server-tier. In other words, we show how to write a servlet to do the same things that could be done with the standalone Java application with the advantage that the application is now Internet enabled.


Software Requirements

List the softwares required for configuring and running this sample application.

Terminology

Term Definition
Folder where OC4J is installed. For example, in Windows it is D:\oc4j and in Linux it is /home/oc4j.

J2EE Home Folder which is part of OC4J installation. For example, in Windows it is D:\oc4j\j2ee\home and in Linux it is /home/oc4j/j2ee/home.

Folder where the Hotel Servlet sample will be unzipped. For example,in Windows it is C:\OTNSamples and in Linux it is /home/OTNSamples.
Folder where Java is installed. For example, in Windows it is C:\jdk1.3 and in Linux it is /usr/jdk1.3.
Folder where the ANT is installed. For example, in Windows it is C:\ant and in Linux it is /home/ant.

Extracting the source code

Execute the following command to extract the sample application.
 
> jar -xvf HotelServlet.jar

The above command extracts all the sample files to HotelServlet folder. Click here to view the directory structure and description of sample files.

Configuring the Application

Preparing the Database :

Ensure that 'Travel Schema' is loaded into the database. For more details about loading the Travel Schema Click here.

Deploying and Running the Application

The application can be deployed and run in either of the following ways:

Deploying and Running the application using Oracle9i JDeveloper

This section describes the steps required for deploying and running this application using Oracle9i JDeveloper.

Step 1:. Open the <SAMPLE_HOME>/HotelServlet/HotelServlet.jws in Oracle9i JDeveloper . The workspace contains HotelServlet.jpr (project file), Servlet files and other files.

Step 2: Create Database Server Connection 

  1. Select Database Server under the Connections Node.
  2. Right click on Database Servers and select "New Connection".
  3. In Step 1 of the wizard, Enter the Connection Name as 'Travel'.
  4. In Step 2 of the wizard, Provide 'travel' as user name and password for the travel schema. (by default travel).
  5. In Step 3 of the wizard, Provide the appropriate database connection information where travel schema is loaded.  
  6. In Step 4 of the wizard, Test the connection and Select 'Finish' button 

Step 3: Right click HotelServlet.jpr and select "Make HotelServlet.jpr". This compiles all the java classes in the project.

Step 4: Right click HotelServlet.jpr and select "Run HotelServlet.jpr". This opens up the browser and runs the HotelServlet

Deploying and Running the application using ANT

This section describes the steps required in deploying this application to the Standalone OC4J using ANT Tool.

Step 1:  SET Environment Variables

  1. Open the Command Prompt and Go to the <SAMPLE_HOME>/HotelSerlvet directory
  2. Ensure that <JAVA_HOME>/bin is in the PATH
  3. Ensure that <ANT_HOME>/bin is in the PATH

Step 2:  Build the EAR file  

From <SAMPLE_HOME>/HotelServlet, execute ant 
 
<SAMPLE_HOME>/HotelServlet> ant 

    This will create the HotelServlet.ear file.

Step 3: Having created a HotelServlet.ear file, to deploy this application to Standalone OC4J, use the following command, from <SAMPLE_HOME>/HotelServlet directory.
 
> java -jar <OC4J_HOME>/j2ee/home/admin.jar ormi://localhost:23791 admin <oc4j password> -deploy -file <SAMPLE_HOME>/HotelServlet/HotelServlet.ear -deploymentName HotelServlet
Example:

On Windows,
> java -jar D:\oc4j\j2ee\home\admin.jar ormi://localhost:23791 admin welcome -deploy -file C:\OTNSamples\HotelServlet\HotelServlet.ear -deploymentName HotelServlet
On Linux,
> java -jar /home/oc4j/j2ee/home/admin.jar ormi://localhost:23791 admin welcome -deploy -file /home/OTNSamples/HotelServlet/HotelServlet.ear -deploymentName HotelServlet

Step 4:  Now, bind the web application using the following command.
 
> java -jar <OC4J_HOME>/j2ee/home/admin.jar ormi://localhost:23791 admin <oc4j password> -bindWebApp HotelServlet HotelServlet-web
http-web-site /HotelServlet
Example:

On Windows,
> java -jar D:\oc4j\j2ee\home\admin.jar ormi://localhost:23791 admin welcome -bindWebApp HotelServlet HotelServlet-web http-web-site /HotelServlet
On Linux,
> java -jar /home/oc4j/j2ee/home/admin.jar ormi://localhost:23791 admin welcome -bindWebApp HotelServlet HotelServlet-web http-web-site /HotelServlet

Now, the application is deployed to the Standalone OC4J. 

Step 5:  Add data source to the application

Execute the following command, substitute database host name, database listening port and database sid appropriately.
 
> java -jar <OC4J_HOME>/j2ee/home/admin.jar ormi://localhost:23791 admin <oc4j password> -application HotelServlet-installDataSource -url jdbc:oracle:thin:@<DB_HOST>:<DB_PORT>:<DB_SID> -location jdbc/TravelDS -username travel -password <schema password> -connectionDriver oracle.jdbc.driver.OracleDriver -className oracle.jdbc.pool.OracleConnectionPoolDataSource 
For example, on Windows
> java -jar D:\oc4j\j2ee\home\admin.jar ormi://localhost:23791 admin welcome -application HotelServlet -installDataSource -url jdbc:oracle:thin:@demo.oracle.com:1521:orcl -location jdbc/TravelDS -username travel -password travel -connectionDriver oracle.jdbc.driver.OracleDriver -className oracle.jdbc.pool.OracleConnectionPoolDataSource 
on Linux,
> java -jar /home/oc4j/j2ee/home/admin.jar ormi://localhost:23791 admin welcome -application HotelServlet -installDataSource -url jdbc:oracle:thin:@demo.oracle.com:1521:orcl -location jdbc/TravelDS -username travel -password travel -connectionDriver oracle.jdbc.driver.OracleDriver -className oracle.jdbc.pool.OracleConnectionPoolDataSource 

Step 6:  Open your favorite browser and access the sample, using the following url.

http://<host_name>:<port>/HotelServlet/HotelServlet

where, <host_name> is the machine on which OC4J is running and <port> is Port to which the OC4J server listens to HTTP requests. Default HTTP Listening port is 8888. 

For example,

http://demo.oracle.com:8888/HotelServlet/HotelServlet


Sample Application Files 

This section will provide a tabular listing of the sample application files, along with their respective directory locations and a description of their roles in the overall scheme of the application.

Directory File Description
build.xml This XML file is used by ANT to create the application ear file
HotelServlet.jws JDeveloper WorkSpace File
HotelServlet.jpr JDeveloper Project file 
Hotel.java This java interface defines the functionalities provided by the system
HotelDetails.java This class is the object representation of Hotel which contains details about the Hotel in the system.
HotelJDBC.java This class interacts with the database and implements the functionalities provided by the interface
HotelServlet.java This is the servlet class is invoked when the browser submits the request..
HotelServletHTML.java This class generates the HTML for the servlet's response.
HotelSummary.java This class is the java object representation of the Hotel Summary. It contains hotel id , name and address of the hotel.
ReservationDetails.java This class is the object representation of the Hotel Reservation details.
RoomType.java This class is the object representation of the Hotel Room Types.
config This directory contains application.xml
Readme.html This file. It contains description about the sample and steps to deploy and run the sample.
images This directory contains Hotel Reservation System Logo Image
WEB-INF This directory contains application.xml and web.xml

 


Please enter your comments about this sample application here.

 

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy