All Examples  All WebLogic Enterprise Connectivity Examples

WebLogic Enterprise Connectivity JSP Stateless Session Bean Example

examples.wlec.jsp.statelesssessionbean

  • statelessSessionBean.jsp (listing)
  • About This Example

    This example demonstrates how to use WebLogic Enterprise Connectivity (WLEC) to access a WebLogic EnterpriseTM (WLE) Enterprise Java Bean (EJB) from a JavaServer Page (JSP) on WebLogic ServerTM (WLS). The example combines a WLS JSP and the WLE Stateless Session Bean example.

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

     

    JSP Stateless Example

     

    When you run the WLEC JSP Stateless Session Bean 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:

      • Buy shares of stock.
      • 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.

    How To Use This Example

    This section describes how to set up and run the JSP Stateless Session Bean 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.

    Setting Up the Example

    1. Build and run the WLE Stateless Session Bean sample.

      See the Stateless Session Bean 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 environment as described in Setting Your Development Environment.

    3. 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.

    4. Add %SERVER_CLASSES%\ejb_basic_statelessSession.jar (NT) or $SERVER_CLASSES/ejb_basic_statelessSession.jar (UNIX) to WEBLOGIC_CLASSPATH.

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

    5. Initialize an IIOP connection pool by modifying the weblogic.properties file.

      You can uncomment and edit the weblogic.CORBA.connectionPool.StatelessSessionpool property in the weblogic.properties file. See Setting Up WebLogic Enterprise Connectivity.

    6. Enable the JSP by uncommenting the following properties in the weblogic.properties file:

      weblogic.httpd.register.*.jsp=\
      	
      weblogic.servlet.JSPServlet
      weblogic.httpd.initArgs.*.jsp=\
      pageCheckSeconds=1,\
      compileCommand=c:/java/bin/javac.exe,\
      workingDir=/weblogic/myserver/classfiles,\
      verbose=true

      Make sure compileCommand points to a valid Java compiler. See Setting Up WebLogic JSP in the Administrator's Guide.

    7. Make sure the document root is configured correctly. Look for the following property in the weblogic.properties file:

      weblogic.httpd.documentRoot=public_html

      The JSP file must be in a directory that is below the document root directory. The document root is the top level directory for files that are publicly available on WLS. It is the root directory from which WLS looks for JSP files. See Setting Up the Document Root.

      1. Set the document root to public_html.

      2. Create the following directory if it does not already exist:

        On Windows NT:

            %WL_HOME%\myserver\public_html\jsp

        On UNIX:

            $WL_HOME/myserver/public_html/jsp

    8. Copy the statelessSessionBean.jsp file to %WL_HOME%\myserver\myserver\public_html\jsp (NT) or $WL_HOME/myserver/myserver/public_html/jsp (UNIX).

    Running the Example

    1. Modify classpaths:

      • Add wleorb.jar to CLASSPATH in %WL_HOME%\setenv.cmd (NT) or $WL_HOME/setenv.sh (UNIX).

      • Add %WL_HOME%\lib\wleorb.jar (NT) or $WL_HOME/lib/wleorb.jar (UNIX) to JAVACLASSPATH.

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

      • Add %WL_HOME%\lib\wlepool.jar (NT) or $WL_HOME/lib/wlepool.jar (UNIX) to WEBLOGIC_CLASSPATH.

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

      For information about setting classpaths for WLS, see Setting Up and Starting WebLogic Server.

    2. Start WLS in your server shell.

    3. Start a Web browser and enter the URL for statelessSessionBean.jsp. For example:

      http://localhost:7001/jsp/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.

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

    Related Documents

    For information about WLS JSPs:

    For information about WLE EJBs:

    For information about the WLE Stateless Session Bean example:

    See also Using WebLogic Enterprise Connectivity.

     

    Copyright © 2000 BEA Systems, Inc. All rights reserved.
    Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.
    Last updated 4/25/00