Java Cookbook : Hotel Reservation System using JSP Java Cookbook : Hotel Reservation System using JSP



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 JavaServer Pages technology using the Hotel Reservation System. The JSP's acts as view, which interacts with the user. The core business logic in this sample is held in the HotelBean, which process data in the database.

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. In windows environment, this file can also be opened using Winzip utility.
> jar -xvf Hrs.jar

The above command extracts all the sample files to Hrs 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>/Hrs/Hrs.jws in Oracle9i JDeveloper. The workspace contains Hrs.jpr (project file), JSP 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 Hrs.jpr and select "Make Hrs.jpr". This compiles all the java classes in the project.

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

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>/Hrs 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>, execute ant 
 
<SAMPLE_HOME>/Hrs> ant 

    This will create the Hrs.ear file.

Step 3: Having created a Hrs.ear file, to deploy this application to Standalone OC4J use the following command, from <SAMPLE_HOME>/Hrs directory.
 
> java -jar <OC4J_HOME>/j2ee/home/admin.jar ormi://localhost:23791 admin <oc4j password> -deploy -file <SAMPLE_HOME>/Hrs/Hrs.ear -deploymentName Hrs
For example, on Windows
> java -jar D:\oc4j\j2ee\home\admin.jar ormi://localhost:23791 admin welcome -deploy -file C:\OTNSamples\Hrs\Hrs.ear -deploymentName Hrs
on Linux ,
> java -jar /home/oc4j/j2ee/home/admin.jar ormi://localhost:23791 admin welcome -deploy -file /home/OTNSamples/Hrs/Hrs.ear -deploymentName Hrs

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 Hrs Hrs-web http-web-site /Hrs
Example:

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

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, database sid and TRAVEL schema password appropriately.
 
> java -jar <OC4J_HOME>/j2ee/home/admin.jar ormi://localhost:23791 admin <oc4j password> -application Hrs -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 
Example:

On Windows,
> java -jar D:\oc4j\j2ee\home\admin.jar ormi://localhost:23791 admin welcome -application Hrs -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 Hrs -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>/Hrs/MainPage.jsp

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/Hrs/MainPage.jsp


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 what they do 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
Hrs.jws JDeveloper WorkSpace File
Hrs.jpr JDeveloper Project File
HeaderBean.java This bean displays header for all the web pages.
HotelBean.java This bean contains the business logic for HRS.

AddNew.jsp

This JSP is used to add new hotels into the system
BookingOptions.jsp This JSP displays hotels and options to Reserve and Cancel bookings
ErrorHandler.jsp This JSP handles the JSP runtime errors.
HotelBookingsView.jsp This JSP displays HTML form for the user to reserve/cancel hotel bookings
HotelInfo.jsp This JSP displays Hotel Information and the Room Availability Information
HotelUpdate.jsp This JSP allows user to update Hotel Information
HrsStatic.jsp This JSP is included in all the JSP. It contains bean declarations.
InfoOptions.jsp This JSP displays options to view Hotel Details and Hotel Room Availability Details
MainPage.jsp This JSP is the main page for the Hotel Reservation System
UpdateOptions.jsp This JSP display options to update Room rates, Room availability and To Add new room type.
images This directory contains Hotel Reservation System Logo Image
WEB-INF This directory contains web.xml
config This directory contains application.xml
Readme.html This file. It contains description about the sample and steps to deploy and run the sample.


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