4 Replies Latest reply on Nov 17, 2001 2:47 PM by Jason Bliss

    Error locating utility bean from JSP

    Jason Bliss Newbie

      I am getting the following errors when I view my JSP

      javax.servlet.ServletException: Cannot create bean of class com.clarkbw.jbeans.ListBooksBean
      at _0002flistBooks_0002ejsplistBooks_jsp_0._jspService(_0002flistBooks_0002ejsplistBooks_jsp_0.java:76)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(JspServlet.java:130)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:282)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
      at org.apache.tomcat.core.Handler.service(Handler.java:287)
      at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
      at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
      at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
      at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
      at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
      at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
      at java.lang.Thread.run(Thread.java:484)

      I use a simple javabean to to access the EJB called ListBooksBean. This bean is called from the following JSP

      <%@ page language="java" contentType="text/html" %>
      <%@ page import="com.clarkbw.bids.*, com.clarkbw.jbeans.*" %>





      <h2>List Bids</h2>

      <jsp:useBean id="list" class="ListBidsBean" />



      I am using JBoss version 2.4.3 w/ Tomcat and this is the structure of my WAR file

      The ListBooksBean is located in the WEB-INF/lib/ejb-client.jar
      There is nothing in the MANIFEST.MF

      [ejb@quagmire jsp]$ jar tvf dist/lib/usedbooks.war
      0 Fri Nov 16 01:13:10 EST 2001 META-INF/
      0 Wed Nov 07 18:54:44 EST 2001 css/
      0 Fri Nov 16 01:13:10 EST 2001 dist/
      0 Fri Nov 16 01:13:10 EST 2001 lib/
      0 Fri Nov 16 01:11:00 EST 2001 WEB-INF/
      0 Tue Oct 30 21:27:40 EST 2001 WEB-INF/lib/
      0 Wed Nov 07 18:54:44 EST 2001 css/general.css
      1212 Fri Nov 16 01:12:40 EST 2001 build.xml
      534 Sat Nov 10 23:09:36 EST 2001 .nbattrs
      1070 Fri Nov 16 01:13:10 EST 2001 lib/ejb-client.jar
      597 Tue Oct 30 22:13:10 EST 2001 WEB-INF/jboss-web.xml
      3417 Fri Nov 16 01:11:00 EST 2001 WEB-INF/web.xml
      1323 Wed Nov 07 19:27:10 EST 2001 listBids.jsp
      1564 Fri Nov 16 00:05:32 EST 2001 listBooks.jsp
      735 Fri Nov 16 00:06:42 EST 2001 addBid.jsp
      1070 Thu Nov 15 23:19:04 EST 2001 addBook.jsp
      352 Fri Nov 16 00:02:04 EST 2001 index.html
      1070 Fri Nov 16 01:13:10 EST 2001 WEB-INF/lib/ejb-client.jar
      43 Fri Nov 16 01:13:10 EST 2001 META-INF/MANIFEST.MF

      If you have any ideas that may help please reply

      If you have any questions you can view the full documentation at http://bryanwclark.com/~ejb/jboss/

        • 1. Re: Error locating utility bean from JSP
          Dan Christopherson Newbie

          Your bean class needs to be in the war file, either in a jar in WEB-INF/lib or as a bare .class file in the proper directory structure under WEB-INF/classes

          • 2. Re: Error locating utility bean from JSP
            Andreas Schaefer Apprentice

            There are some steps you can do:

            1) Some Tomcat versions have problems with /WEB-INF/lib therefore unpack the JAR file and it to /WEB-INF/classes

            2) Why does the Servlet complains that the ListBooksBean could not be created ? It does not know it because you create ListBidsBean. Please catch an exception when you create ListBidsBean (if one is thrown) and show it here. Also provide the constructor(s) of the JavaBean "ListBidsBean".

            Andy

            • 3. Re: Error locating utility bean from JSP
              Jason Bliss Newbie

              I am sorry for the mistake, I pasted the wrong JSP... It should import com.clarkbw.books.* and call ListBooksBean. As fof unpacking the JAR file into the WEB-INF/classes it has the same exceptions.

              • 4. Re: Error locating utility bean from JSP
                Jason Bliss Newbie

                The ListBooksBean:

                package com.clarkbw.jbeans;

                import javax.naming.*;
                import java.rmi.*;
                import javax.rmi.*;
                import javax.ejb.*;
                import javax.servlet.jsp.*;
                import java.util.Collection;

                //import com.clarkbw.books.*;

                /** JavaBean for use in a JSP page to reference the ListBooksEJB
                */
                public class ListBooksBean implements java.io.Serializable {

                /** User ID to get books of
                */
                private int userId;
                /** ListBooks reference
                */
                // private ListBooks listbooks;

                /** Constructor does the JNDI lookups
                * @throws JspException Any error in EJB's
                */
                public ListBooksBean() throws JspException {
                // System.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
                // System.setProperty("java.naming.provider.url","localhost:1099");
                // try {
                // Context jndiContext = new InitialContext();
                // Object ref = jndiContext.lookup("ListBooksEJB");
                // ListBooksHome home = (ListBooksHome)PortableRemoteObject.narrow(ref,ListBooksHome.class);
                // ListBooksHome home = (ListBooksHome)new InitialContext().lookup("ListBooksEJB");

                // listbooks = home.create();

                // } catch ( NamingException e ) {
                // throw new JspException("ListBooksBean: NamingException: " + e.getMessage());
                // } catch ( CreateException e ) {
                // throw new JspException("ListBooksBean: CreateException: " + e.getMessage());
                // } catch ( RemoteException e ) {
                // throw new JspException("ListBooksBean: RemoteException: " + e.getMessage());
                // }
                }

                /** Sets User ID
                * @param userId User ID to set
                */
                public void setUserId(int userId) {
                this.userId = userId;
                }

                /** Gets Books for User ID
                * @throws JspException Any error with EJB's
                * @return Collection of Books
                */
                public Collection getBooks() throws JspException {
                // try {
                // return listbooks.getBooks(new Integer(userId));
                return new java.util.ArrayList();
                // } catch ( RemoteException e ) {
                // throw new JspException("ListBooksBean:getBooks RemoteException: " + e.getMessage());
                // }
                }
                }