Hello ! The problem of JNDI access through JSP !
jonathan78wong Jun 28, 2003 5:44 AMDear all ,
Hello ! I create and deploy a jar in JBoss-3.2.1 (without Tomcat) . I have a JSP as follow :
<%@ page
session="false"
isThreadSafe="true"
isErrorPage="false"
import="javax.naming.*, com.sample.*, javax.rmi.PortableRemoteObject, java.util.*, java.io.*, javax.net.*"
%>
<h4>test</h4>
test
<%
try {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "127.0.0.1:1099");
properties.put(Context.URL_PKG_PREFIXES, "org.JBoss.naming:org.jnp.interfaces");
InitialContext lContext = new InitialContext(properties);
Object objref = lContext.lookup("HelloWorldRef");
HelloWorldHome lHome = (HelloWorldHome) PortableRemoteObject.narrow(objref, HelloWorldHome.class);
HelloWorld lSession = lHome.create();
String fromEJB = lSession.hello();
out.println( "" + fromEJB);
}
catch( Exception e ) {
out.println( "Caugth exception: " + e.getMessage() );
e.printStackTrace();
}
and the web.xml in :
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<display-name>Welcome to EJB</display-name>
<ejb-ref>
<ejb-ref-name>HelloWorld</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
com.sample.HelloWorldHome
come.samlpe.HelloWorld
<ejb-link>HelloWorld</ejb-link>
</ejb-ref>
</web-app>
and the jboss.xml in jar :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web
PUBLIC "-//JBoss//DTD Web Application 2.3//EN"
"http://www.jboss.org/j2ee/dtds/jboss-web_3_0.dtd">
<enterprise-beans>
<ejb-name>HelloWorld</ejb-name>
<jndi-name>jb/HelloWorldHome</jndi-name>
</enterprise-beans>
and the ejb-jar.xml in jar :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
JBoss Hello World Application
<display-name>Hello World EJB</display-name>
<enterprise-beans>
<ejb-name>HelloWorld</ejb-name>
com.sample.HelloWorldHome
com.sample.HelloWorld
<ejb-class>com.sample.HelloWorldBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</enterprise-beans>
</ejb-jar>
I place the web.xml in WEB-INF and EJBs in WEB-INF\classes
However , Tomcat says :
Caugth exception: HelloWorldRef not bound
Therefore , what should I do to correct it ? Thank you !