This tutorial covers creating a EJB 3.1 application that demonstrates the no-interface Local view of a Session Bean and WAR-based packaging.
Time to Complete
Approximately 45 minutes.
This example demonstrates the simplified programming and packaging model changes provided in EJB 3.1. Since the mandatory use of Java interfaces has been removed in EJB 3.1, plain old Java objects can be annotated and used as EJB components. It also supports the ability to place EJB components directly inside Web applications, thereby removing the need to produce archives to store the Web and EJB components and combine them together in an enterprise archive (EAR) file.
Normally, accessing this bean from a Servlet would require one .war, ejb-jar, and an .ear file to wrap the two modules together. With the new packaging alternative, everything fits into a single .war thus reducing the complexity of JEE development.
In this tutorial, you will create a Java EE 6 Web Application
and add the following components to it - no-interface
view Stateless Session Bean, Servlet and a
index.jsp will contain
a form with a submit button, Run, allowing you to execute
the application. The form will submit to a Servlet which
method in Session bean you will create and the response is
In the Web Application you will create
,@Stateless annotation is provided to
an plain old Java class that exposes it as an EJB session
bean. This is then injected into an Servlet using an
@EJB annotation. The EJB session bean and Servlet
classes are then packaged and deployed together in a single WAR
file, which demonstrates the simplified packaging and deployment
changes available in Java EE 6.
- Each session bean exposes a no-interface Local view.
- This client view has the same semantics as the EJB 3.0 Local business interface, except that it does not require a separate interface.
- All public methods of the bean class are automatically exposed to the caller.
- By default, any session bean that has an empty implements clause and does not define any other Local/Remote client views exposes a no-interface client view.
- A client of the no-interface view always acquires an EJB reference, either through injection or JNDI lookup.
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.
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 no-interface stateless session bean, perform the following steps in NetBeans IDE.
To create a Servlet, perform the below steps in NetBeans IDE.
To create response.jsp, perform the following steps in
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.
In this tutorial, you have learned how to:
- Create a no-interface View Session Bean-
@Statelessannotation is provided to an plain old Java class that exposes it as an EJB session bean.
- Access the Session Bean in a Servlet
- Package the application as a WAR file and deploy.
- JSR 318: Enterprise JavaBeans 3.1
- Enterprise JavaBeans Technology
- Creating 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.