Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing an EJB into a JSP

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I deployed an EJB in WebLogic5.1 and Configured the property file of the weblogic to support JSP and I created a JSP file and plased it in the dir c:\weblogic\myserver\public_html. then I can access it from the localhost:7001\myjsp.jsp. But if i want use that EJB in a JSP, I want Help where to place the Bean class (i am asking the compleate path)and where will it needs to put the jar file and also what will be the package i need to plase in the JSP file. Can any one help me (if possable with a sample code) Thanks in advance.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am moving this post to J2EE and EJB forum.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Yugandhar",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
 
Hemanth Varadhan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Yugandhar:
I deployed an EJB in WebLogic5.1 and Configured the property file of the weblogic to support JSP and I created a JSP file and plased it in the dir c:\weblogic\myserver\public_html. then I can access it from the localhost:7001\myjsp.jsp. But if i want use that EJB in a JSP, I want Help where to place the Bean class (i am asking the compleate path)and where will it needs to put the jar file and also what will be the package i need to plase in the JSP file. Can any one help me (if possable with a sample code) Thanks in advance.

Hi Yugandhar
You have to deploy those EJB first,after deploying u can refer to those ejb from the jsp file just as u do from any other ckient say servlet,the client code below does the same
**********-------------***********
Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
ctx = new InitialContext(ht);
Object obj = ctx.lookup("JNDIBeanNAme");
BeanHome home=(BeanHome) PortableRemoteObject.narrow(obj,BeanHome.class);
**********-------------***********
From this you can refer to the ejb,you will also have to import the following pacakages
****-------****
javax.ejb.*;
javax.rmi.RemoteException;
javax.naming.*;
****-------****
Hope this helps!
hemanth
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic