1 Reply Latest reply on Sep 9, 2004 6:08 PM by Darran Lofthouse

    JSP Access to Session Bean

    Brian Allen Newbie

      Can someone please confirm what is required to use a session Bean from a JSP, all deplayed on JBoss 3.2.5.

      I'm continually getting
      Error.javax.naming.NameNotFoundException: comp not bound

      I've got the default jndi.properties file in conf in the classpath.

      Also tried this method in the JSP:
      public static Context getInitialContext() throws javax.naming.NamingException {
      java.util.Properties p = new java.util.Properties();
      p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
      p.put(Context.PROVIDER_URL, "localhost:1099");
      return new javax.naming.InitialContext(p);

      Code segment in the JSP
      try {
      Context jndiContext = getInitialContext();
      Object ref = jndiContext.lookup("java:comp/env/ejb/UnwyAppHome");

      UnwyAppHome home = (UnwyAppHome)
      UnwyApp unwyApp = home.create();

      Then added a jboss.xml although I thought it was optional.
      <?xml version = '1.0' encoding = 'windows-1252'?>
      <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd">





      <?xml version = '1.0' encoding = 'windows-1252'?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

      Session Bean ( Stateful )


        • 1. Re: JSP Access to Session Bean
          Darran Lofthouse Master

          Get rid of the 'java:comp/env/ejb/' in your lookup unless you have defined an ejb-ref in your web.xml

          Also get rid of setting properties for the InitialContext constructor, the default will be fine.

          Also what do you mean by the default jndi.properties is on the classpath, the server will have already managed that for you.