[jboss-user] [EJB 3.0] - Re: how to access more than one EJB containers in one JSP
ALRubinger
do-not-reply at jboss.com
Sun Jun 10 09:52:46 EDT 2007
Haven't checked this in an IDE or anything, but this should get you the idea. Keeping in mind that business functions like obtaining and calling upon EJB3 services shouldn't really be taking place in the view layer...
<%!
| private YourEjbInterface1 ejb1 = null;
| private YourEjbInterface2 ejb2 = null;
|
| public void jspInit () {
| try {
|
| // Define the Connection Properties
| Properties props1 = new Properties();
| props1.put(InitialContext.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
| props1.put(InitialContext.PROVIDER_URL, "jnp://yourHost1:yourPort1");
| props1.put(InitialContext.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
|
| Properties props2 = new Properties();
| props2.put(InitialContext.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
| props2.put(InitialContext.PROVIDER_URL, "jnp://yourHost2:yourPort2");
| props2.put(InitialContext.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
|
|
| // Define the Context for Servers
| Context ctx1 = new InitialContext(props1);
| Context ctx2 = new InitialContext(props2);
|
| // Look up the EJB3 Proxies in JNDI
| ejb1 = (YourEjbInterface1) ctx.lookup("ejb1/jndi/name");
| ejb2 = (YourEjbInterface2) ctx.lookup("ejb2/jndi/name");
|
| } catch (Exception e) {
| e.printStackTrace ();
| }
| }
| %>
|
| Invoke 1:
|
| <% ejb1.myMethod(); %>
|
| Invoke 2:
|
| <% ejb2.myMethod(); %>
|
|
S,
ALR
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4052904#4052904
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4052904
More information about the jboss-user
mailing list