Intermediate JSP Sample : Managing Multiple Components

Previous Contents Next

This sample implements a hotel reservation system. It combines several different components, including:

  • Hotel Enquiry Component, which supports queries about hotel details and room availability.
  • Hotel Reservation Component, which enables users to make and cancel hotel room reservations.
  • Hotel Information Component, which enables system administrators to manage data describing the hotels in the system.

OTN provides three versions of this sample: one using JSPs and JavaBeans, and two using JSPs and EJBs accessed via Custom Tag libraries, EJB Utility Tags.

JSPs and JavaBeans

Contents

Purpose

Simulate a hotel reservation system using JSPs and JavaBeans.

Remarks

Both the presentation and the business logic are done through JSPs and JavaBeans. This demonstrates the use of these elements of OC4J JSP:

  • Oracle JML tags
  • Session-based connection (one database connection per session).

Code from MainPage.jsp

...
<%@ page import="HotelBean" %>
...
    <jml:when condition = "<%= l_reqType.equals(\"HOTELS\") %>" >
<%--
If the value of the parameter REQ_TYPE is "HOTELS" then,
return the source for the right frame of the main page.
Right frame contains the list of all Hotels available.
For getting the hotels list the method getHotels() in
the HotelBean class is called.
--%>
<BODY bgcolor="#bfbfbb">
<SCRIPT LANGUAGE="JavaScript1.1">
function putVal(val1) {
document.forms[0].HOTEL_ID.value =val1;
}
</SCRIPT>
<CENTER>
<FORM>
<%= hrsBean.getHotels() %>
<BR>
<input type=hidden name=HOTEL_ID value="">
</FORM>
</CENTER>
</BODY>
</jml:when> ...

 

Source Code Listings

JSPs and EJBs accessed via Custom Tag libraries

Contents

Purpose

Simulate a hotel reservation system using JSPs and EJBs accessed via Custom Tag Libraries.

Remarks

This sample illustrates EJB features including:

  • Locating and instantiating EJB components.
  • Creating and using custom tag libraries from a JSP client to call methods on an EJB component.
  • A JSP client that accesses EJBs from OC4J(Oracle9iAS Containers for J2EE).

Code from EjbHotels.java

...  

/**
* This method is executed at the start of the Tag. This calls the
* method to initialize the EJB remote and home interface and also
* processes the requests passed from the JSPs. Depending on the
* Request Type, this method calls the other methods and prints out
* the required HTML String using the JSP Writer
**/
public int doStartTag() throws JspException {
initEJB(); // Initialize
EjbHrsBean l_ejbHrs = new EjbHrsBean(); // Instantiate the Bean
JspWriter out = pageContext.getOut(); // Instantiate the JSP Writer

try {
if (m_reqType.equals("HOTELS")) {
// Calling the getAllHotels() method to get all the hotels
m_hotels = m_remoteInterface.getAllHotels() ;
// Print the HTML String
out.print(l_ejbHrs.generateAllHotelsHTML(m_hotels));
}
else if (m_reqType.equals("HOTEL_DETAILS")) {
// Get the Hotel Details using getHotelDetails method
if (m_hotelDetails == null ||
m_hotelDetails.m_hotelID != m_hotelId){
m_hotelDetails = m_remoteInterface.getHotelDetails(m_hotelId);
}
// Print the HTML String
out.print(l_ejbHrs.generateHotelDetailsHTML(m_hotelDetails));
}
...
}
catch (Exception e) {
e.printStackTrace();
return SKIP_BODY;
}
return EVAL_BODY_INCLUDE;
}

 

Source Code Listings

EJB Source

 

JSPs and EJBs accessed via EJB Utility Tags.

Contents

Purpose

Simulate a hotel reservation system using JSPs and EJBs accessed via EJB Utility tags in OC4J JSP.

Remarks

This sample illustrates EJB features including:

  • Locating and instantiating EJB components.
  • Using the OC4J JSP EJB Utility tags from a JSP client to call methods on an EJB component.
  • A JSP client that accesses EJBs from OC4J(Oracle9iAS Containers for J2EE).

Code from MainPage.jsp

...  
    <jml:when condition = "<%= l_reqType.equals(\"HOTELS\") %>" >
<%--
If the value of the parameter REQ_TYPE is "HOTELS" then,
return the source for the right frame of the main page.
Right frame contains the list of all Hotels available.
--%>
<BODY bgcolor="#bfbfbb">
<SCRIPT LANGUAGE="JavaScript1.1">
function putVal(val1) {
document.forms[0].HOTEL_ID.value =val1;
}
</SCRIPT>
<CENTER>
<FORM>
<%--
Instantiate the Session EJB for getting the hotel details
--%>
<ejb:useHome id="hotelSystemHome" type="HrsEjb.HotelSystem.ejb.HotelSystemHome"
location="java:comp/env/ejb/HotelSystem" />
<ejb:useBean id="hotelSystemRemote" type="HrsEjb.HotelSystem.ejb.HotelSystem" scope="session" >

<ejb:createBean instance="<%=hotelSystemHome.create()%>" />
</ejb:useBean>

<%--
Call EJB method getAllHotels() and pass the return value to the
ejbHrs bean method to generate the HTML for the list of all hotels
--%>
<%= ejbHrs.generateAllHotelsHTML(hotelSystemRemote.getAllHotels())%>
<BR>
<input type=hidden name=HOTEL_ID value="">
</FORM>
</CENTER>
</BODY>
</jml:when> ...

 

 

Source Code Listings

EJB Source


Previous Contents Next
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