WebLogic Server 6.0.0 Code Examples, BEA Systems, Inc.

Package examples.wlec.jsp.statelesssessionbean

This example demonstrates how to use WebLogic Enterprise Connectivity to access a WebLogic Enterprise EJB from a JavaServer Page on WebLogic Server.

See:
          Description

JSP StatelessSessionBean Example Summary
StatelessSessionBean An HTML front end that submits information to a JSP. The JSP sends the input data to a WebLogic Enterprise EJB. The EJB handles the request by buying or selling shares of stock. The EJB returns the results to the servlet, which compiles the returned data into a dynamically-generated HTML file and sends the file to the client browser.
 

Package wlec.jsp.statelesssessionbean Description

This example demonstrates how to use WebLogic Enterprise Connectivity to access a WebLogic Enterprise EJB from a JavaServer Page on WebLogic Server. The example combines a WLS JSP and the WLE StatelessSessionBean example.

The following figure illustrates the WLEC JSP Stateless Session Bean example.

 

JSP Stateless Example

 

When you run the WLEC JSP StatelessSessionBean example, the following events occur:

  1. At startup, WLS creates a WLEC Internet Inter-ORB Protocol (IIOP) connection pool for the WLE Trader domain.

    The remaining steps are performed at run time.

  2. The Internet client sends a request to a JSP.

  3. The WLS JSPServlet finds the JSP file and uses the JSP compiler to compile the JSP file into a servlet class.

  4. Acting as a WLE client, the servlet:

    1. Calls getInitialContext to:

      1. Obtain a connection from the IIOP connection pool.
      2. Perform a JNDI lookup for the Trader EJB home interface.
      3. Activate the connection to the Trader domain.

    2. Uses the Trader EJB home interface to create a remote interface for the Trader EJB.
    3. Uses the Trader EJB remote interface to invoke the Trader EJB.

  5. The Trader EJB performs operations and returns results to the servlet. The Trader EJB can perform two operations:

    1. Buy shares of stock.
    2. Sell shares of stock.

  6. The servlet:

    1. Uses the Trader EJB remote interface to remove the Trader EJB from the EJB server.
    2. Compiles the results into a dynamically-generated HTML page.
    3. Sends the page to the Internet client.

The following section describes how to build and run the example:

  1. Prerequisites
  2. Build the Example
  3. Configure the Server
  4. Run the Example

Prerequisites

Install and set up the following:

See Platform Support for WebLogic Enterprise Connectivity for information about the supported versions for each of these products.

Build the Example

  1. Build and run the WLE StatelessSessionBean sample.

    See the StatelessSessionBean Sample Application in the WLE documentation:

    1. Go to J2EE Topics on the Web.
    2. Scroll down and click Sample Applications.
    3. Scroll down and click Stateless Session Bean Sample.

    The build procedure for the Stateless Session Bean sample generates the ejb_basic_statelessSession.jar file. This .jar file contains the stubs, skeletons, and classes necessary for the JSP to act as a client to the Stateless Session Bean sample.

  2. Set up your WLS development shell as described in Setting up your environment for building and running the examples.

  3. Modify classpaths:

    1. Add %WL_HOME%\lib\wleorb.jar to CLASSPATH in %WL_HOME%\config\examples\setExamplesEnv.cmd (NT) or $WL_HOME/config/examples/setExamplesEnv.sh (UNIX).

    2. Add %WL_HOME%\lib\wleorb.jar (NT) or $WL_HOME/lib/wleorb.jar (UNIX) to CLASSPATH in the start script.

      If you are going to start WLS by running startExamplesServer, set CLASSPATH in the startExamplesServer.cmd file (NT) or the startExamplesServer.sh file (UNIX). Otherwise, set CLASSPATH by means of another method such as the command line or the NT System Properties dialog box.

    3. Add %WL_HOME%\lib\wlepool.jar (NT) or $WL_HOME/lib/wlepool.jar (UNIX) to CLASSPATH in the start script.

      If you are going to start WLS by running startweblogic, set CLASSPATH in the startweblogic.cmd file (NT) or the startweblogic.sh file (UNIX). Otherwise, set CLASSPATH by means of another method such as the command line or the NT System Properties dialog box.

    Note: You need to add RemoteObjectReference class to your classpath in start script. This class is bundled under wlej2eecl.jar file in WLE 5.1 and under m3.jar file in WLE 5.0.

    %TUXDIR%\udataobj\java\jdk\wlej2eecl.jar

    where:

    %TUXDIR%
    Your WLE installation directory.

    For information about setting CLASSPATH for WLS, see Setting up your environment for building and running the examples.

  4. Copy the ejb_basic_statelessSession.jar file to your WLS SERVER_CLASSES directory, where SERVER_CLASSES is an environment variable that you set when you set up your development environment.

  5. Add %SERVER_CLASSES%\ejb_basic_statelessSession.jar (NT) or $SERVER_CLASSES/ejb_basic_statelessSession.jar (UNIX) to CLASSPATH.

    CLASSPATH is an environment variable in the startWebLogic.cmd file (NT) or the startWebLogic.sh file (UNIX).

  6. Copy the StatelessSessionBean.jsp file located in the samples/examples/wlec/jsp/statelesssessionbean directory in your WebLogic Server installation to the config/examples/applications/examplesWebApp directory in your WebLogic Server installation. This directory is the location of the publically-available files of the examplesWebApp.

Configure the Server

  1. Initialize an IIOP connection pool:
    1. Start the server with the examples configuration in a new command shell.
    2. Bring up the Administration Console in your browser.
    3. Click to expand the Services node in the left-hand pane.
    4. Click to expand the WLEC node in the left-hand pane.
    5. Select the StatelessSessionPool node.
    6. Select the Configuration tab in the right-hand pane to display the General and Security tab.
    7. Select the General tab to display the Primary and Failover addresses.
    8. Change the Primary Addresses and Failover Addresses from [//wlehost:2468] to [//host:port].

      where:

      host
      The name of the local machine.
      port
      The TCP port number at which the ISL process listens for incoming requests; it must be a number between 0 and 65535. The default value is 2468.
    9. Note: If you are running the example on UNIX change the Domain from [ejbsample] to [simpapp]. NT user can leave the Domain to the default Domain id [ejbsample].
    10. Click the Apply button to save the assignment.
    11. Select the Targets tab in the right-hand pane to display the Available and Chosen targets.
    12. Move the examplesServer from the Target column to the Chosen column and click the Apply button to save the assignment.

  2. Make sure that the examplesWebApp is deployed on your server.

Run the Example

  1. Start a web browser and enter the URL for StatelessSessionBean.jsp.

    For example:

    http://localhost:7001/examplesWebApp/StatelessSessionBean.jsp

    The JSP servlet provides the required inputs to the EJB. The inputs consist of a customer name, number of shares, stock symbol, and type of trade (buy or sell) for a number of transactions.

  2. Watch for the results, which consist of a cumulative cash balance maintained by the servlet for all trades.

There's More...

Read more about:


Documentation is available at
http://e-docs.bea.com/wls/docs60/

Copyright © 2000 BEA Systems, Inc. All rights reserved.