JSP编程指南(第二版)中的例子运行错误

nu 2004-08-03 03:23:37
有人看这本书吗,帮俺分析一下

第24章j2EE中的JSP,我从网上下的源码,在浏览器访问:http://127.0.0.1:8080/ch24/index.jsp出错:

org.apache.jasper.JasperException: interface com.wrox.store.ejb.cart.Cart : java.lang.InstantiationException: com.wrox.store.ejb.cart.Cart
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)

注:我执行test和upload是正常的
...全文
90 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
nu 2004-08-09
  • 打赏
  • 举报
回复
没人理我?是不是问题太简单了?~!!
nu 2004-08-04
  • 打赏
  • 举报
回复
我是按照书上的步骤做的,运行提供的test.java是成功的,说明ejb部署没有问题,下面我详细说一下环境:

平台为:win2000+tomcat4.1.30+jboss2.4.10

index.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吗,到底是怎么实现的?

盼赐教!
BillyW 2004-08-03
  • 打赏
  • 举报
回复
很想帮你,不过......

你的环境需要描述一下,布署过程也需要描述。

最好把你的部署描述符贴出来。
hq1305018 2004-08-03
  • 打赏
  • 举报
回复
EJB部属了没?
AlexSunny 2004-08-03
  • 打赏
  • 举报
回复
com.wrox.store.ejb.cart.Cart 这个有问题

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧