This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Tomcat and the fly likes EJB reference not bound Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "EJB reference not bound" Watch "EJB reference not bound" New topic
Author

EJB reference not bound

john d
Greenhorn

Joined: Jul 11, 2002
Posts: 9
I'm running JBoss 3.0.1 with Tomcat 4.0.4 bundle. I have successfully deployed a EJB to Jboss and created 2 clients (java & JSP client).
For some reasons, I'm able to run the java client but when I try the JSP client (served by Tomcat) I get this error message
javax.servlet.ServletException: Name greetings is not bound in this Context
Below is the code for the 2 clients & web.xml
<----------- jsp client -------------->
<%@ page import="javax.naming.*,
java.util.*,
java.util.Hashtable,
javax.rmi.PortableRemoteObject,
com.stardeveloper.ejb.session.*"%>
<%
long t1 = System.currentTimeMillis();
InitialContext ctx = new InitialContext();
Object ref = ctx.lookup("ejb/First");
FirstHome home = (FirstHome) PortableRemoteObject.narrow (ref, FirstHome.class);
First bean = home.create();
String time = bean.getTime();
bean.remove();
ctx.close();
long t2 = System.currentTimeMillis();
%>
<html>
<head>
<style>p { font-family:Verdana;font-size:12px; }</style>
</head>
<body>
<p>Message received from bean = "<%= time %>".<br>Time taken :
<%= (t2 - t1) %> ms.</p>
</body>
</html>

<----------- java client ------------->
import javax.naming.*;
import com.stardeveloper.ejb.session.*;
import java.util.Hashtable;
import javax.rmi.PortableRemoteObject;
import com.stardeveloper.ejb.session.*;
class firstEJBclient {
public static void main(String[] args) {
try {
long t1 = System.currentTimeMillis();
InitialContext ctx = new InitialContext();
System.out.println("Got CONTEXT");

Object ref = ctx.lookup("ejb/First");
System.out.println("Got REFERENCE");

FirstHome home = (FirstHome) PortableRemoteObject.narrow (ref, FirstHome.class);
First bean = home.create();
String time = bean.getTime();
bean.remove();
ctx.close();
long t2 = System.currentTimeMillis();
System.out.println("Message received from bean = "+time+" Time taken : "+(t2 - t1)+" ms.");
}
catch (Exception e) {
System.out.println(e.toString());
}
}
}

<----------------- web.xml -------------------->
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<session-config>
<session-timeout>
1800
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
firstEJB2.jsp
</welcome-file>
</welcome-file-list>
<ejb-ref>
<description>A reference to an entity bean</description>
<ejb-ref-name>ejb/First</ejb-ref-name>
<ejb-ref-type>Stateless</ejb-ref-type>
<home>com.stardeveloper.ejb.session.FirstHome</home>
<remote>com.stardeveloper.ejb.session.First</remote>
</ejb-ref>
</web-app>
Why is it not bound?
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

The name it's not finding is 'greetings'. Where in the JSP are you trying to get this?
Leonid Eremin
Greenhorn

Joined: Aug 04, 2004
Posts: 1
Same problem with JSP on Apache tomcat 5.0 and session bean on WebLogic:
part of my JSP:

<%
try{
Properties env = /*System.getProperties();*/ new Properties();
env.put(Context.PROVIDER_URL, "t3://localhost:7001");
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "weblogic");
env.put(Context.SECURITY_CREDENTIALS, "weblogic");
Context ctx = new InitialContext(env);
Object ref = ctx.lookup("sample.MyFirstSession");
MyFirstSessionHome home = (MyFirstSessionHome) PortableRemoteObject.narrow(ref, MyFirstSessionHome.class);
MyFirstSession sess = home.create();
%><%=sess.giveMeSomething()%><%
}catch(Exception e){
%><%=e.toString()%><%
}
%>

What's the problem in?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: EJB reference not bound
 
Similar Threads
EJB reference not bound
Stateful Session Beans..Help needed.
EJB reference not bound in JSP
Facing Problem in Deploying EJB in Jboss 4.2.2 GA
RMI error: Name is not bound in this Context