如何在servlet中调用Local接口的session Bean? 难道是不能从servlet中调用吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 try { Context context = new InitialContext(); Object object = context.lookup("CreateRecord"); CreateRecordHome Home = (CreateRecordHome) PortableRemoteObject.narrow(object, CreateRecordHome.class); createRecord = Home.create(); System.out.println("Instantiated UserSession and CreateRecord reference"); } catch (Exception e) { System.out.println(e.getMessage()); } 楼上的老兄, CreateRecordHome Home = (CreateRecordHome) PortableRemoteObject.narrow(object, CreateRecordHome.class);这一条语名是在用Remote接口时用的,难道用local接口也必须有这一句吗? 严格来说Servlet不应该调用Local接口的SessionBean这个设计是不合理的如果Web服务器和Application服务器不用同一个JVM可定出错 把楼上的gks_cn(981530)兄的CreateRecordHome Home = (CreateRecordHome) PortableRemoteObject.narrow(object, CreateRecordHome.class);去掉narrow方法应该可以了,即CreateRecordHome Home = (CreateRecordHome)(object, CreateRecordHome.class);试试吧!看行不行 A_Liang(阿亮) CreateRecordHome Home = (CreateRecordHome)(object, CreateRecordHome.class);你的这行代码是不是写错了。?! 对不起,考错了!CreateRecordHome Home = (CreateRecordHome)context.lookup("CreateRecord"); javax.naming.Context ctx = new javax.naming.InitialContext(); dhfx.entity.TsInfoLocalHome th = (dhfx.entity.TsInfoLocalHome) ctx.lookup("local:ejb/ejb/dhfx/entity/TsInfoLocalHome"); dhfx.entity.TsInfoKey key = new dhfx.entity.TsInfoKey(tsNo); dhfx.entity.TsInfoLocal tl = th.findByPrimaryKey(key); wobensuren(丑得杀死你) 老兄的写法是在SessionBean中调用EntityBean的方法。我试过的,Bean与Bean之间通过Local接口都可以调用成功(包括一个SessionBean调用另一个SessionBean),但是在Servlet中不管怎么调用Local接口的Bean都会抛出java.lang.ClassCastException异常来。难道在servlet中不可以调用Local接口的Bean吗?可在servlet的Web.xml文件中却有Local EJb Refenerces的项?是不是说不在Web.xml文件中定义Local EJB References就不能调用Local接口的EJB吗?可是在Web.xml中也有EJB References的项,那个我也没有定义它,可我却能调用Remote接口的EJB。谁能给我一个调试成功的在servlet中调用Local接口的EJB的例子?(希望能带上ejb-jar.xml和web.xml) 将Servlet和EJB封装在一个EAR中,可能就行了。 我也试着把serlvet和EJB装在一个ear中了,可还是不行呀。 楼主把你的调用代码贴出来吧,另外,jar和servlet各自放在哪里? 终于解决了。原来是JBuilder7的一个Bug.我一直是在JBuilder7中运行试验的。一旦把servlet和EJB部署到AppServer上就一点问题都没有了。 -- * 求助 2011.11.7 * -- 关于 HttpClient 和 Cookie 的问题。 关于上传图片的问题 为什么调用ftpClient.printWorkingDirectory()返回的是NULL 大家帮看一下 求教 求(java中)在网页中直接打开word文档的方案? 关于文字过滤的方法 在JSP中,下面这段代码如何解释? 用java org.apache.axis.wsdl.Java2WSDL 命令出错 在用JBuilder8+weblogic7.0开发的struts模式中如何引用EJB? EJB问题 闲题:女人和哥们! 谁有XML SPY5.0的注册号!!!
{
Context context = new InitialContext();
Object object = context.lookup("CreateRecord");
CreateRecordHome Home = (CreateRecordHome) PortableRemoteObject.narrow(object, CreateRecordHome.class);
createRecord = Home.create();
System.out.println("Instantiated UserSession and CreateRecord reference");
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
CreateRecordHome Home = (CreateRecordHome) PortableRemoteObject.narrow(object, CreateRecordHome.class);
这一条语名是在用Remote接口时用的,难道用local接口也必须有这一句吗?
这个设计是不合理的
如果Web服务器和Application服务器不用同一个JVM可定出错
CreateRecordHome Home = (CreateRecordHome) PortableRemoteObject.narrow(object, CreateRecordHome.class);去掉narrow方法应该可以了,即
CreateRecordHome Home = (CreateRecordHome)(object, CreateRecordHome.class);试试吧!看行不行
CreateRecordHome Home = (CreateRecordHome)(object, CreateRecordHome.class);
你的这行代码是不是写错了。?!
dhfx.entity.TsInfoLocalHome th = (dhfx.entity.TsInfoLocalHome) ctx.lookup("local:ejb/ejb/dhfx/entity/TsInfoLocalHome");
dhfx.entity.TsInfoKey key = new dhfx.entity.TsInfoKey(tsNo);
dhfx.entity.TsInfoLocal tl = th.findByPrimaryKey(key);
谁能给我一个调试成功的在servlet中调用Local接口的EJB的例子?(希望能带上ejb-jar.xml和web.xml)
我一直是在JBuilder7中运行试验的。一旦把servlet和EJB部署到AppServer上就一点问题都没有了。