Sun Java System Application Server 

Samples Index

The Stateless Simple EJB Sample Application

The HelloWorld Stateless Simple EJB application is a basic example of a J2EE application that uses servlets, an EJB, and Java Server Pages. The EJB is a stateless session bean.

Building, Deploying, and Running the Application

The general instructions for building, deploying, and running sample applications are provided in Building, Deploying, and Running Sample Applications. In reading this document, use the following application-specific variables for this application:

Follow this general procedure:

  1. Build the Application. The build file, build.xml, is in the app_dir directory, specifically, install_dir/samples/ejb/stateless/apps/simple.
  2. Deploy the Application. The EAR file is install_dir/samples/ejb/stateless/apps/simple/stateless-simple.ear.
  3. Run the Application. The URL is http://hostname:port/helloworld.

Understanding the Application

When you load the application URL shown above, you will see the main page that prompts you to enter your name. Enter a name and press the Process button. Pressing a button invokes a servlet. The servlet calls a stateless session bean, which returns a greeting to the servlet based upon the current system time. Then the servlet dispatches a JSP page to deliver the greeting to the browser that depends on the time of day ("Good morning," "Good afternoon," and so on).

This application is an example of a Model/View/Controller (MVC) design pattern, as illustrated in the figure below. Each part of an MVC design has an independent role:

As depicted in this diagram, pressing the "Process" button in the main page invokes a servlet, the application "controller." The servlet calls a stateless session bean (the "model") to determine a greeting based upon the current system time. The servlet dispatches a JSP page (the "view") to deliver the greeting back to the browser.


Copyright © 2006 Sun Microsystems, Inc. All rights reserved.