Managing Session Timeouts in Servlets- Shopping Cart Application - Readme

Managing Session Time-outs in Servlets - Shopping Cart Application - Readme

Date: 15/03/2004

Table of Contents

Introduction
Application Overview
Application Design
Sample Application Files
Setting Up the Sample Application
Additional References

Introduction 

Prerequisite 

To understand this sample you need to have expertise in working with Servlets and knowledge of Enterprise Java Beans. Refer to the Additional References section for related resource links.

Technical Overview 

In this sample application we demonstrate how a web application can make use of servlet life cycle event listeners to manage session time-outs. An event is a notification of change in the state of a servlet's life cycle. The application events provide notifications of a change in state of the servlet context  or of an HTTP session object. These events can be captured and monitored by defining listener objects, whose methods get called when such events occur.

For servlet context events, the event listener classes can receive notification when the web application is deployed or is being undeployed, and when attributes are added, removed, or replaced.  Servlet context listeners manage resources at the application level.

For HTTP session events, the event listener classes can receive notification when an HTTP session is created, invalidated or timed out and when an HTTP session attribute is added, removed, or replaced. Session listeners manage resources associated with the single user's session.

In this sample application we have implemented sessionDestroyed() method of HttpSessionListener to remove the Stateful Session Beans when the user session expires.

Application Overview 

The sample application allows following functionalities,
  • Login
  • Browse though the available products
  • Create shopping cart
  • Update the cart
  • Remove items from the cart
  • Checkout the cart
  • Logout

Application Design 

This application is designed to demonstrate how HttpSessionListener can be used to release any references to the external resources stored in the http session, when the session times out.  The application uses a Stateful Session Bean to store the shopping cart information for the user. When the user creates a cart for the first time, a reference to the ShoppingCartBean is stored in the HttpSession object. This reference is made use to serve the subsequent requests when the user adds, modifies or deletes items in the shopping cart. The session bean instances are removed in the sessionDestroyed() method of  SessionTimeoutListener class when the user logs out from the application or the session times out. 

Sample Application Files 

This section provides 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:

Readme file and Stylesheets

Directory File Description

SessionListener/doc

Readme.html

This file

SessionListener/doc Install.html                                            
The sample installation document

SessionListener/doc

otn.css                                   
Stylesheet used in the Readme.html and Install.html


Servlet and Java source files

Directory File Description

SessionListener/src/oracle/otnsamples/servlets       

ShoppingCartServlet.java

This Servlet displays the various screens of the application

SessionListener/src/oracle/otnsamples/servlets EditCart.java
The servlet used to manage the shopping cart in the HTTP Session
SessionListener/src/oracle/otnsamples/servlets SessionTimeoutListener.java The listener class that implements the HttpSessionListener interface.
SessionListener/src/oracle/otnsamples/servlets        
ProductDetails.java
The Java class used to hold product information
SessionListener/public_html/WEB-INF
web.xml
The web deployment descriptor


Enterprise Java Beans and related files

Directory File Description
SessionListener/src/oracle/otnsamples/ejb        ShoppingCartBean.java                       
The bean implementation class
SessionListener/src/oracle/otnsamples/ejb ShoppingCartLocalHome.java
The local home class
SessionListener/src/oracle/otnsamples/ejb ShoppingCartLocal.java
The local interface class
SessionListener/src/oracle/otnsamples/ejb InvalidValuesException.java
The application level exception thrown by the EJB
SessionListener/src/META-INF ejb-jar.xml
The EJB deployment descriptor
SessionListener/src/META-INF orion-ejb-jar.xml
Server specific deployment descriptor



Other configuration and build files

 Directory File Description

SessionListener

build.xml

The ant project build file     

SessionListener/src/META-INF                       
data-sources.xml                                     
The configuration file, where the datasource used by this application is defined

Setting up the Sample Application 

Refer the Install.html for step-by-step instructions on extracting files, installing and running the sample successfully.

Additional References 

We hope you find this README file helpful. Please enter your comments about this sample in the OTN Sample Code Discussion Forum.


SessionListener Sample Application

Please rate this sample application :
Excellent
Good
Average
Below Average
Poor

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