How to call ejbs from jsp?

Questions by sadashivarao   answers by sadashivarao

Showing Answers 1 - 7 of 7 Answers

pavan

  • Oct 8th, 2006
 

 
<%
InitialContext jndiContext = new InitialContext(properties);
System.out.println("Got JNDICcontext");

// Get a reference to the Bean name from ejb-config.xml
Object ref = jndiContext.lookup("Processor");
System.out.println("Got reference of JNDIContext");

// Get a reference from this to the Bean's Home interface
ProcessorHome prhome = (ProcessorHome)
PortableRemoteObject.narrow (ref,ProcessorHome.class);

// Create an Adder object from the Home interface
Processor sp = home.create();
%>

  Was this answer useful?  Yes

Rizwan

  • Feb 7th, 2007
 

First approach is also correct.

But in that approach you have use narrow method

whereas in this case you dont need it.

By using this approach also we can call EJB from a jsp



initalContext ic=new initicalContext();

// creating an initialcontext

objecthomeBean bean=(homeBean)ic.lookup("jndiname");

// getting Home interface

objectremoteBean=bean.create();

// getting remote object from home interface

  Was this answer useful?  Yes

bassem.aly

  • Jun 2nd, 2010
 

You have two option.

If the EJB is local (in the same EAR) you will use @EJB
If the EJB outside ear you will lookup in Application server context.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions