hi all,
I am using j2sdkee1.3 and jsdk1.3. I want my
servlet to call the bean.
i hope something like this will work..in my
jsp but what about the generated
XYZClient.jar file, where should i keep it?
how will this work?...
<%@ page import="javax.naming.*"%>
<%@ page import="javax.rmi.PortableRemoteObject"%>
<%@ page import="java.util.Properties"%>
<%@ page import="com.nabil.ejb.Adder"%>
<%@ page import="com.nabil.ejb.AdderHome"%>
<%
// preparing a Properties object for constructing
// an initial context
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.SerialInitContextFactory");
properties.put(Context.PROVIDER_URL, "iiop://localhost:1050");
try {
// Get an initial context
InitialContext jndiContext = new InitialContext(properties);
System.out.println("Got context");
// Get a reference to the Bean
Object ref = jndiContext.lookup("Adder");
System.out.println("Got reference");
// Get a reference from this to the Bean's Home interface
AdderHome home = (AdderHome)
PortableRemoteObject.narrow (ref, AdderHome.class);
// Create an Adder object from the Home interface
Adder adder = home.create();
out.println ("2 + 5 = " + adder.add(2, 5));
}
catch(Exception e) {
System.out.println(e.toString());
}
%>