All Examples All WebLogic Enterprise Connectivity Examples
WebLogic Enterprise Connectivity JSP Stateless Session Bean Example
examples.wlec.jsp.statelesssessionbean
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.
When you run the WLEC JSP Stateless Session Bean example, the following events occur:
- 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.
- The Internet client sends a request to a JSP.
- The WLS JSPServlet finds the JSP file and uses the JSP compiler to compile the JSP file into a servlet class.
- Acting as a WLE client, the servlet:
- Calls getInitialContext to:
- Obtain a connection from the IIOP connection pool.
- Perform a JNDI lookup for the Trader EJB home interface.
- Activate the connection to the Trader domain.
- Uses the Trader EJB home interface to create a remote interface for the Trader EJB.
- Uses the Trader EJB remote interface to invoke the Trader EJB.
- 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.
- The servlet:
- Uses the Trader EJB remote interface to remove the Trader EJB from the EJB server.
- Compiles the results into a dynamically generated HTML page.
- 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:
- WebLogic Server (WLS)
- Java Development Kit (JDK)
- WebLogic Enterprise (WLE)
See Platform Support for WebLogic Enterprise Connectivity for information about the supported versions for each of these products.
Setting Up the Example
- Build and run the WLE Stateless Session Bean sample.
See the Stateless Session Bean Sample Application in the WLE documentation:
- Go to J2EE Topics on the Web.
- Scroll down and click Sample Applications.
- 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.
- Set up your WLS development environment as described in
Setting Your Development Environment.
- 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.
- 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).
- 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.
- 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.
- 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.
- Set the document root to public_html.
- 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
- 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
- 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.
- Start WLS in your server shell.
- 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.
- 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:
- The WLE EJB Programming Environment:
- Go to Getting Started on the Web.
- Click The WLE EJB Programming Environment.
- Designing and Developing EJBs for the WLE System:
- Go to Getting Started on the Web.
- Scroll down and click Designing and Developing EJBs for the WLE System.
- Building and Deploying EJBs:
- Go to Getting Started on the Web.
- Scroll down and click Building and Deploying EJBs.
- J2EE Topics on the Web.
For information about the WLE Stateless Session Bean example:
- Stateless Session Bean Sample Application:
- Go to J2EE Topics on the Web.
- Scroll down and click Sample Applications.
- Scroll down and click Stateless Session Bean Sample.
- Overview of EJB Sample Applications:
- Go to J2EE Topics on the Web.
- Scroll down and click Sample Applications.
- Scroll down and click Overview of EJB Sample Applications.
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
|