SessionBean+CMP开发时遇到的问题,恳请大虾们指点~! Collection接口不能执行序列化,它无法在网络中(不同的jvm中)传递你必须用其他方法来封装需要传递的数据。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Enumeration好像是Jdk1.0里面的一个老式序列化接口吧,恳请做过SessionBean调用CMP中查找方法的大虾们指点~~~ 可以用jb自动生成的sessionfacade,它会自动把cmp的findby返回的集合包裹成为一个对象数组,然后从session bean中返回给客户端,这样在客户端调用就应该没有问题了 在Collection col=pro.findByXx(xx);前面加上Collection col=new ArrayList(); sorry!!!写错了,应该是Collection col1=new ArrayList();然后再把col里的值放到col1中,return col1; 好像也不行,coll.addAll(col)是不是这样放进去的~楼上那位大哥不是说在JBuilder里面自动生成sessionfacade,能不能说得详细点,谢谢~! 如果你使用jb开发,在servlet里面调用,我教你:) 问题1: CMP作为"Remote"接口,定义"findByXx()"方法后编译出错,但改为"Local"接口编译部署就可以了,是不是CMP中的"findByXx()"方法不支持远程调用; 我可以保证CMP的findByXx()肯定.支持1. classHome接口必须是Remote2.findByXX()throw xxx.Remote接口3.classBean中findByXX()throw xxx.Remote3.看配置文件为Remote<remote>classHome</remote><remote>classBean</remote>................问题2: SessionBean调用CMP的"findByXx()",再用客户端调用SessionBean的时,运行客户端无结果,代码如下:Product pro;//Product为CMP接口;SessionBean中调用CMP的"findByXx()"代码:Collection col=null; public java.util.Collection queryByXx(java.lang.String xx){ try{ Collection col=pro.findByXx(xx); }catch(Exception e){} return col; }客户端调用SessionBean中的"queryByXx()"代码: Collection col=manage.queryByXx(xx); Iterator itr=col.iterator(); while(itr.hasNext()){ Product pro=(Product)itr.next(); System.out.println(pro.getXx()); }改为:在问题1必须解决使有该方法你可是client调用呀,必须用远程接口客户端调用SessionBean中的"queryByXx()"代码: Collection col=manage.queryByXx(xx); Iterator itr=col.iterator(); while(itr.hasNext()){ Product pro=(Product)javax.rmi.PortableObject.narrow(itr.next(),Product.class)); System.out.println(pro.getXx()); } 楼上的大哥,你说的方法还是不行,问题不在“Product pro=(Product)java.rmi.PortableRemoteObject.narrow(itr.next,Product.class));小弟再演示下我的代码:SessionBean:queryByXx():public java.util.Collection queryByXx(java.lang.String xx){ try{ Collection col=proHome.findByXx(xx);//proHome为CMP的Home接口 System.out.println("col.size() : "+col.size());//测试"col"是否有数据,本例中有数据 return col; }catch(Exception e){ return null;}}Client:Collection col=SesssionBean.queryByXx(xx);System.out.println("Test Success");//不知为什么,把这条语句放在Col前面肯定是没问题的,但要是放在他后面就不显示结果,也就意味着之后的语句都没有执行System.out.println("Client col.size() : "+col.size());//没显示Iterator itr=col.iterator();while(itr.hasNext()){ Product p=(Product)PortableRemoteObject(itr.next(),Product.class); System.out.println(p.getXx()+" "+p.getXxx());}本程序在SessionBean中测试结果显示正常,可以排除其他代码出问题的可能性,恳请各位再帮忙看看~! Collection col=SesssionBean.queryByXx(xx);改为:Collection col=(Collection )SesssionBean.queryByXx(xx); try! Collection col=SesssionBean.queryByXx(xx);System.out.println("Test Success");//不知为什么,把这条语句放在Col前面肯定是没问题的,但要是放在他后面就不显示结果,也就意味着之后的语句都没有执行在执行Collection col=SesssionBean.queryByXx(xx);之后抛异常了么 我的问题和你差不多.我有点奇怪.CMP作为LOCAL接口.在对话BEAN作为返回,那么就要在JSP中进行调用此CMP.那不变成JSP可以调用LOCAL的CMP?????这道理说不上去,谁能解释下 也可以实现,如将jar保和war包打入ear包中,但我不退间这种模式,还是在session中完成调用cmp(local),同时session将数据放入dto中放回 请楼主贴一下你的代码,客户端调用SessionBean之前,是如何初始化SessionBean的 berl88(berl) : 我也来说两句,你这样会出错的,在会话bean调用cmp返回时应该把数据封装一下再返回,这样就没问题的,你用一下jbuilder就知,它会报错的 请问各位用的是什么方法解决SessionBean调用CMP中的查找方法的呢? 你可以这样啊,在SessionBean中定义一个Collection的成员变量,定义返回Collection的成员变量的远程方法,将cmp中find方法返回的Collection遍历之后一个一个的写入Collection的成员变量,然后里在客户端就可以用调用Collection的成员变量的远程方法来获取 求大侠支援,hibernate+jap 怎么调用视图 望大家指点一二!!! 类的加载有什么作用? 问个关于jms/mdb的问题,谢谢 Quartz的疑问 操作oracle数据库报的怪异的错误,麻烦高手给看看 来点有难度的,跨页面贴图 js跨域单点登录不安全,怎么解决 J2EE安装和编译问题,在线等待 需要写一个bat文件,去关闭应用程序的bat窗口 请问哪有java编程思想(第二版)的中文电子版或chm格式的下载? 用struts,采用MVC模式,对数据查询显示的页面中我想加入checkbox来控制删除功能?
Collection col=new ArrayList();
应该是Collection col1=new ArrayList();
然后再把col里的值放到col1中,return col1;
楼上那位大哥不是说在JBuilder里面自动生成sessionfacade,能不能说得详细点,谢谢~!
CMP作为"Remote"接口,定义"findByXx()"方法后编译出错,但改为"Local"接口编译部署就可以了,是不是CMP中的"findByXx()"方法不支持远程调用;
我可以保证CMP的findByXx()肯定.支持
1. classHome接口必须是Remote
2.findByXX()throw xxx.Remote接口
3.classBean中findByXX()throw xxx.Remote
3.看配置文件为Remote
<remote>classHome</remote>
<remote>classBean</remote>
................问题2:
SessionBean调用CMP的"findByXx()",再用客户端调用SessionBean的时,运行客户端无结果,代码如下:
Product pro;//Product为CMP接口;
SessionBean中调用CMP的"findByXx()"代码:
Collection col=null;
public java.util.Collection queryByXx(java.lang.String xx){
try{
Collection col=pro.findByXx(xx);
}catch(Exception e){}
return col;
}
客户端调用SessionBean中的"queryByXx()"代码:
Collection col=manage.queryByXx(xx);
Iterator itr=col.iterator();
while(itr.hasNext()){
Product pro=(Product)itr.next();
System.out.println(pro.getXx());
}
改为:
在问题1必须解决使有该方法你可是client调用呀,必须用远程接口
客户端调用SessionBean中的"queryByXx()"代码:
Collection col=manage.queryByXx(xx);
Iterator itr=col.iterator();
while(itr.hasNext()){
Product pro=(Product)javax.rmi.PortableObject.narrow(itr.next(),Product.class));
System.out.println(pro.getXx());
}
小弟再演示下我的代码:
SessionBean:queryByXx():
public java.util.Collection queryByXx(java.lang.String xx){
try{
Collection col=proHome.findByXx(xx);//proHome为CMP的Home接口
System.out.println("col.size() : "+col.size());//测试"col"是否有数据,本例中有数据
return col;
}catch(Exception e){
return null;
}
}
Client:
Collection col=SesssionBean.queryByXx(xx);
System.out.println("Test Success");//不知为什么,把这条语句放在Col前面肯定是没问题的,但要是放在他后面就不显示结果,也就意味着之后的语句都没有执行
System.out.println("Client col.size() : "+col.size());//没显示
Iterator itr=col.iterator();
while(itr.hasNext()){
Product p=(Product)PortableRemoteObject(itr.next(),Product.class);
System.out.println(p.getXx()+" "+p.getXxx());
}
本程序在SessionBean中测试结果显示正常,可以排除其他代码出问题的可能性,恳请各位再帮忙看看~!
改为:
Collection col=(Collection )SesssionBean.queryByXx(xx); try!
System.out.println("Test Success");//不知为什么,把这条语句放在Col前面肯定是没问题的,但要是放在他后面就不显示结果,也就意味着之后的语句都没有执行
在执行Collection col=SesssionBean.queryByXx(xx);
之后抛异常了么
我有点奇怪.
CMP作为LOCAL接口.在对话BEAN作为返回,那么就要在JSP中进行调用此CMP.
那不变成JSP可以调用LOCAL的CMP?????
这道理说不上去,谁能解释下
但我不退间这种模式,还是在session中完成
调用cmp(local),同时session将数据放入
dto中放回