Home

It is assumed that the reader knows how to create an Enterprise Application and to add J2EE modules into it. To know more click here. So you created an Enterprise Application and added an EJB module and a Web module to it. Here we will discuss how to call a “Session Bean” from the web module.

Select the web module and select “New” -> “Servlet”.

Now fill servlet specific information in the next window.

Click “Next” for adding other servlet related information like “Url pattern(s)”, “Servlet Name” these details will be stored in the web.xml file, configuration file of the web module.

Servlet will be added to web module with some basic code.

Open the Servlet file by clicking on it. Then right click “Select Enterprise Bean” -> “ Call Enterprise Bean ”.

A window will be displayed showing information of EJB’s in the project. Select one you want to call with referred interface, As EJB can be called remotely or locally.

Click “OK”. A private method for remote lookup will be generated, so in “processRequest” method we can call that private method to return remote reference and on that EJB remote instance any of the EJB business methods can be invoked. We will invoke “sayWelcome” method that is assumed to be already added.

Now right click “Enterprise Application” icon and click “Run project”. EJB and web module will be deployed automatically. If application server is not running it will also be started.

In “Console” window you can see EJB has been deployed and NetBeans will automatically run the web module.

Use new servlet URL to run your servlet that has code of EJB client we added. You can see the remote method results there.

Related Posts:

Creating a Session Ejb in NetBeans IDE

Adding Business Methods to an EJB in NetBeans

Creating J2ee Modules In NetBeans IDE

Developement Of Enterprise Applications in NetBeans IDE

How To Add Fields And Generating Getter-Setters

How To Edit/Add JSP Pages in NetBeans IDE

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Calling A Session Bean Using A Web Module

Name (required)

Mail (will not be published) (required)

Website

Anti-spam word (required)

Application Frameworks (0)

C/C++ Pack (0)

Debugging (0)

Java EE (5)

Java ME (0)

Java SE (0)

NetBeans IDE (6)

NetBeans Platform (0)

News (0)

Plugins (0)

Profiler (0)

Web Services (0)

Subscribe in a reader

Enter your email address to subscribe to NetBeans Blog by Email:

NetBeans

April 2007 (7)

March 2007 (4)

Login

Copyright 2006 - 2007 NetBeans Blog. All rights reserved.