访问EJB时出错,请帮忙

yang_113 2004-06-23 12:47:29
本人写了一个无状态SESSION BEAN ,在SUN APPSERVER 上成功发布,但用WEB方式访问时却出错了.客户端的代码如下:
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
{
String str = "" ;
try
{
Context ct = new InitialContext() ;
Object ob = ct.lookup("HelloBean") ;
if (ob != null )
str = "HelloBean finded\r\n";
HelloHome helloHome = (HelloHome) PortableRemoteObject.narrow(ob, HelloHome.class) ;
str = str +" HelloHome finded\r\n";
Hello hello = helloHome.create();
str = str +"helloHome.create() success\r\n";
str = str +"run hello.sayHello() \r\n";
str = str +hello.sayHello("my boy") ;
str = str + "run success \r\n";
httpServletRequest.setAttribute("message",str);
return actionMapping.findForward("forward");
}
catch(Exception ex)
{
str = str + "cause an exception \r\n";
httpServletRequest.setAttribute("message",str+ex.toString());
return actionMapping.findForward("forward");
}
}
在JSP页面中出现的信息如下:
HelloBean finded cause an exception java.lang.ClassCastException
请问,这是什么原因呢?
...全文
62 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yang_113 2004-06-23
  • 打赏
  • 举报
回复
谢谢!问题已经解决了。是看了SUN的SAMPLE解决的
lukelan 2004-06-23
  • 打赏
  • 举报
回复
你在你的web.xml里加入了对session bean的引用吗?
yang_113 2004-06-23
  • 打赏
  • 举报
回复
从JSP显示的信息来看可以知道是下面这一句有问题:
HelloHome helloHome = (HelloHome) PortableRemoteObject.narrow(ob, HelloHome.class) ;
但我不知道为什么会出问题,问题出在哪里,因为这是很标准的写法啊。
CrazyHippo 2004-06-23
  • 打赏
  • 举报
回复
ClassCastException是类型转换异常,找出出错的位置,多半是上朔或下朔造型不当造成的

67,513

社区成员

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

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