This tutorial covers creating a Session Bean and accessing it in a Web Application using JSP and Servlet.
Time to Complete
Approximately 45 minutes.
Enterprise JavaBeans technology is the server-side component
architecture for developing and deploying business applications
in Java EE. The latest release of the technology, JSR
318: Enterprise JavaBeans 3.1, which is available in the
Java EE 6 platform, further simplifies the technology and makes
many improvements. There are two types of EJB components:
Session beans and Message-driven beans.
In this tutorial, you will create a JEE 6 Web Application and add the following components to it - Stateless Session Bean, a Servlet, and a JSP. The JSP will contain a form allowing you to specify a name. The form will submit to a Servlet which will read the name entered as the form parameter. The Servlet will pass the name to a sayHello method that is in the Session bean that you will create.
Hardware and Software Requirements
The following is a list of hardware and software requirements:
- Download and install Java JDK 7 from this link.
- Download and install NetBeans 7.1.2 with Java EE which includes GlassFish 3.1.2 (Java EE download bundle) from this link. During installation, be sure to check the box to install GlassFish. JUnit is an optional installation and not required for this tutorial
Before starting this tutorial, you should:
- Have the software installed as listed under Hardware and Software Requirements section.
- Ensure NetBeans is running.
- For best results use Firefox or Chrome browsers.
Create a Java EE Web Application
To create a Java EE Web Application, perform the following steps in the NetBeans IDE.
You should now have a Web Application project with an index.jsp file.
Create Session Bean
To create a stateless session bean that is accessed
using the local client access mode, perform the following
steps in NetBeans IDE.
To create a Servlet, perform the below steps in NetBeans IDE.
To modify index.jsp, perform the following steps in
Deploy the Web Application
To deploy and run the application, perform the following steps
in NetBeans IDE.
The output will be as shown below.
In this tutorial, you have learned how to:
- Create a Session Bean.
- Access the Session Bean in a Web Application using Servlet
- JSR 318: Enterprise JavaBeans 3.1
- Enterprise JavaBeans Technology
an Enterprise Application with EJB 3.1
Lead Curriculum Developer: Anjana Shenoy
To help navigate this Oracle by Example, note the following:
- Hiding Header Buttons:
- Click the Title to hide the buttons in the header. To show the buttons again, simply click the Title again.
- Topic List Button:
- A list of all the topics. Click one of the topics to navigate to that section.
- Expand/Collapse All Topics:
- To show/hide all the detail for all the sections. By default, all topics are collapsed
- Show/Hide All Images:
- To show/hide all the screenshots. By default, all images are displayed.
- To print the content. The content currently displayed or hidden will be printed.
To navigate to a particular section in this tutorial, select the topic from the list.