com.wrox.store.ejb.cart.Cart 这个有问题

解决方案 »

  1.   

    我是按照书上的步骤做的,运行提供的test.java是成功的,说明ejb部署没有问题,下面我详细说一下环境:平台为:win2000+tomcat4.1.30+jboss2.4.10index.jsp内容如下:
    <%@ include file="header.jsp" %><P>
    Access the EJBs :
    <UL>
    <LI>In a <A HREF="catalog.jsp?catalogPage=scriptlet.jsp">scriptlet</A></LI>
    <LI>Through a <A HREF="catalog.jsp?catalogPage=bean.jsp">JavaBean wrapper</A></LI>
    <LI>Using <A HREF="catalog.jsp?catalogPage=tag.jsp">custom tags (1)</A></LI>
    <LI>Using <A HREF="catalog.jsp?catalogPage=jndi.jsp">custom tags (2)</A></LI>
    </UL>
    </P><%@ include file="footer.jsp" %>我把第一句注释后,页面可以显示,很明显,是第一句引入文件的问题
    header.jsp内容如下:
    <%-- find the user's cart that is bound to the HTTP sesison --%>
    <jsp:useBean id="cart" class="com.wrox.store.ejb.cart.Cart" scope="session"/><HTML>
    <HEAD>
    <TITLE>Wrox on-line store</TITLE>
    </HEAD><BODY><P>
    <H1>Wrox on-line store</H1>
    </P>显然是第一句的问题,Cart是session bean的远程接口,内容如下:
    package com.wrox.store.ejb.cart;import java.rmi.RemoteException;
    import java.util.*;import com.wrox.store.ejb.customer.Customer;
    import com.wrox.store.ejb.product.Product;
    import com.wrox.store.exception.*;/**
     * This represents the business interface for a shopping cart in
     * our on-line store.
     *
     * @author    Simon Brown
     */
    public interface Cart extends javax.ejb.EJBObject {  /**
       * Adds the specified quantity of the supplied product to the cart.
       *
       * @param product     the Product to be added to the cart
       * @param newQuantity   the quantity of the product to be added
       */
      public void add(Product product, int newQuantity)
        throws RemoteException;  /**
       * Gets a reference to the collection of products in the cart.
       *
       * @return  a Collection of Product instances (or references)
       */
      public Collection getProducts() throws RemoteException;  /**
       * Determines how many of the specified product are in the cart - if any.
       *
       * @param product   the Product to find
       * @return  an int representing the quantity in the cart
       */
      public int getQuantity(Product product)
        throws RemoteException;  /**
       * Gets the total price for this order.
       *
       * @return  a double representing the total price
       */
      public double getTotal() throws RemoteException;  /**
       * Submits the contents of this cart to be purchased. This involves a number
       * of steps including :
       * <OL>
       * <LI>authorising the credit card</LI>
       * <LI>sending a message to the fulfillment centre</LI>
       * <LI>sending a confirmation e-mail to the customer</LI>
       * </OL>
       *
       * @param customer    the Customer that this cart belongs to
       * @throws  AuthorizationException    if the credit card details were
       *                    incorrect or authorization was not given
       */
      public void submitOrder(Customer customer)
        throws AuthorizationException, RemoteException;}还提供了CartBean和home接口CartHome
    描述符ejb-jar.xml片段如下:
    <session>
    <ejb-name>Cart</ejb-name>
    <home>com.wrox.store.ejb.cart.CartHome</home>
    <remote>com.wrox.store.ejb.cart.Cart</remote>
    <ejb-class>com.wrox.store.ejb.cart.CartBean</ejb-class> <session-type>Stateful</session-type>
    <transaction-type>Container</transaction-type>
    </session>我是EJB初学者,按我的理解,错误提示说明是com.wrox.store.ejb.cart.Cart实例化的时候出问题了,也就是这句<jsp:useBean id="cart" class="com.wrox.store.ejb.cart.Cart" scope="session"/>
    我不明白,Cart是个接口,怎么能够被实例化呢,还有这里只提供了home接口没有类,谁来实现它呢?EJB的运作方式是通过home接口调用远程接口,继而调用EJB吗,到底是怎么实现的?盼赐教!