EJB 类型转换异常问题

08-10-30 yongbuyanbai
我写了个简单的EJB 有态BEAN,通过JAVA SE访问没有问题,但是通过JSP页面访问出现了转换异常
java.lang.ClassCastException: $Proxy83
at org.apache.jsp.index_jsp._jspService(index_jsp.java:91)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:595)
BEAN 情况:
public interface ShopCarLocal{
public void addItem(String item);
}
@Stateful
@Remote(ShopCar.class)
public class ShopCar implements ShopCarRemote {
private List<String> items=new ArrayList<String>();

public void addItem(String item)
{
items.add(item);
System.out.println("additem");
}

}
JSP页面
InitialContext context=new InitialContext();

ShopCarRemotef=(ShopCarRemote)context.lookup("ShopCar/remote");
不知道是什么原因,请帮帮忙,谢谢!

xmuzyu
2008-10-31 02:08
>>@Remote(ShopCar.class)改为@Remote(ShopCarRemote.class)试试。你必须要定义一个远程接口,这样部署时,容器会生成客户端的stub,以及服务器端的ejb object.这些都是隐式实现Remote指定的接口的。

Arsenal
2008-10-31 11:19
远程接口指定的是ShopCar.class
@Remote(ShopCar.class)

而查找之后转型为ShopCarRemote,类型不对,当然会报错