Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_java_server thread: JSP calling a EJB thru a Bean


Message #1 by "Vedantam Prasad" <vv.prasad@d...> on Tue, 13 Feb 2001 16:41:07
Hi,
Add j2ee.jar or the jar which contains javax.naming.InitialContext class to 
ur Webserver classpath or lib...
This will slove ur problem
bye now
zen
> Hi,
> 
> I am accessing a Entity Bean(CMP) from a JSP using a worker Bean.
> 
> The worker Bean does the job of creating an initial context, handle to 
> Home thru JNDI, and access to methods like findAll().
> 
> While executing calling thru JSP it gives a 
> error "java.lang.NoClassDefFound" error for javax/naming/InitialContext
> 
> however, if accessed thru another simple java program there is no error. 
> 
> Has anybody tried this flow JSP -> Bean -> EJB
> 
> Pls reply asap.
> 
> Thanks,
> 
> 
> Here is the JSP code
> 
> <%! Enumeration e ; %>
> <%
> try{
> 	e=bfundclient.EjbClientCode();
>     if (e != null) {
>       while (e.hasMoreElements()) {
>       out.println(e.nextElement());
> 	  }
> 	}
> }catch(Exception ex){ex.printStackTrace(); }
> %>
> 
> Part of Bean Code
> 
>     public Context getInitialContext() throws Exception {
>       Properties p = new Properties();
>       p.put(Context.INITIAL_CONTEXT_FACTORY,
>             "weblogic.jndi.WLInitialContextFactory");
>       p.put(Context.PROVIDER_URL, url);
>       return new InitialContext(p);
>     }
> 
> 	public Enumeration EjbClientCode()  throws Exception {
> 		    FundHome home = null ;
> 
> 			try {
> 				Context c = getInitialContext();
> 				home = (FundHome)c.lookup("Fund") ;
> 			}
> 			catch(Exception ep) {
> 				throw new Exception("Lookup failed") ; }
> 
> 			try {
> 				Enumeration e= home.findAll();
> 				return e ;
> 			}
> 			catch(Exception et) {
> 				throw new Exception ("FindBy Method 
> failed") ; }
> 	}
> 

  Return to Index