Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
EJB lookup example 
 

This examples describes you the lookup method used in EJB.

 

EJB lookup example

                         

This examples describes you the lookup method used in EJB.

Bean30Remote.java:-This  is the Remote interface which extends javax.ejb.EJBObject package. These are similar to RMI Remote interface.  The use of remote interface is particularly helpful in  providing business-specific functionality of an EJB. Here @Remote is the annotation used to declare the interface as Remote.

Bean30Remote.java


package ejb;

import javax.ejb.Remote;

@Remote
public interface Bean30Remote {

    String getMessage();

    String getAddress();

    String getCompanyname();
}

Bean30Bean.java:-This is the bean of type session in which we have defined  the body of the method which were declared in the          
interface named SessionBeanRemote.java.@Stateless is the annotation used to declare the bean as a session type.

@Stateless(mappedName="Bean30"):-It is used to change the mapped name from Bean30Bean to Bean30.After this we will use Bean30 to look up the bean in our application client.

Bean30Bean.java


package ejb;

import javax.ejb.Stateless;

@Stateless(mappedName="Bean30")
public class Bean30Bean implements Bean30Remote {

    public String getMessage() {
        return "Roseindia.net";
    }
    public String getAddress() {
        return "Sec-3,D-16/116,Rohini";
    }
    public String getCompanyname() {
        return "Roseindia.net Pvt.Ltd.";
    }
}

Main.java:-This is the client application from which  we can access the methods which are defined in the bean.

InitialContext ctx = new InitialContext():-InitialContext is the class which is used to find out  the starting context for performing naming operations. Initial Context is used to lookup home interfaces with inside an EJB. Here all the naming convention are relative to context. 

Bean30Remote br = (Bean30Remote) ctx.lookup("Bean30"):-This is the method that is used to retrieve the named object i.e. ("Bean30").

Main.java

package ejbmodule30;

import ejb.Bean30Remote;
import javax.naming.InitialContext;

public class Main {

    public static void main(String[] argsthrows Exception {
        InitialContext ctx = new InitialContext();
        Bean30Remote br = (Bean30Remote) ctx.lookup("Bean30");
        System.err.println("=================================");
        System.err.println("EJB message is:" + br.getMessage());
        System.err.println("Company name is:" + br.getCompanyname());
        System.err.println("Address is:" + br.getAddress());
        System.err.println("=================================");
    }
}

Output of the program

=================================
EJB message is:Roseindia.net
Company name is:Roseindia.net Pvt.Ltd.
Address is:Sec-3,D-16/116,Rohini
=================================

Download source code

                         
» View all related tutorials
Related Tags: c database data application io find ejb this app simple tab example to base exam ssi e eps li im

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.