那位给小弟写个调用HelloBean的客户端(jsp)的。

bigbat 2003-08-20 06:56:35
小弟写了一个HelloWorld的bean。但是我用下面的代码

package com.quartz;

/**
* @author Administrator
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
import java.rmi.RemoteException;
import java.util.Hashtable;
import java.util.Properties;

import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;



public class Helloclient {
private static final String JNDI_NAME = "ejb/com/quartz/HelloHome";

private String url;
private HelloHome home;

public Helloclient(String url)
throws NamingException
{

this.url= url;
home = lookupHome();

}

void test() throws RemoteException,CreateException
{
Hello hello = (Hello) PortableRemoteObject.narrow(home.create(), Hello.class);
System.out.println("I am in client. "+hello.sayHello());
}


/**
* 运行这个实例:
* java HelloClient t3://localhost:7001
*/
public static void main(String[] args) throws Exception {

System.out.println("客户端程序测试开始...\n");

String url= "iiop://localhost:2809/";

// 解析命令行
if (args.length != 1) {
System.out.println("用法: java HelloClient iiop://localhost:2809/");
return;
} else {
url = args[0];
}
Helloclient client = null;
try {
client = new Helloclient(url);
} catch (NamingException ne) {
System.exit(1);
}
try {

client.test();
} catch (Exception e) {
System.exit(1);
}
System.out.println("\n客户端程序测试结束...\n");
}


/**
* 查找 EJB 的主接口
*/
private HelloHome lookupHome()
throws NamingException
{
Context ctx = getInitialContext();
Object home = ctx.lookup(JNDI_NAME);
return (HelloHome) PortableRemoteObject.narrow(home, HelloHome.class);
}

/**
* 使用属性对象获取上下文
*/
private Context getInitialContext() throws NamingException {
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
h.put(Context.PROVIDER_URL, url);
return new InitialContext(h);
}
}

但据是不成!
有经验的帮帮忙了!!!!



那位给小弟写个调用HelloBean的客户端(jsp)的。
...全文
40 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ouchaojing 2004-02-11
  • 打赏
  • 举报
回复
把远程对象的根程序和程序框架复制到jsp文件所在的classes目录下。
郝振明 2003-08-27
  • 打赏
  • 举报
回复
应该不是,我没有读你的程序,其实,wsad的测试环境应该能够运行这个程序。
哦,不好意思,没注意,你不是用wsad开发的?你配置了吗??.xml文件
Martin2002 2003-08-27
  • 打赏
  • 举报
回复
不知道你的WebShpere服务器有没有起来,你的HelloWorld客户端程序是要通过在WebSphere中的管理服务器提供的目录服务去查找你需要的资源的.所以如果你的WebSphere服务器没有启动的话,就根本拿不到你想要的资源,因为WebSphere无法为你服务.
一般WebSphere都有两个版本,Single,Advanced,主要有两个不同,Single版本把应用服务器和管理服务器整和在一起.Advancd服务器分为管理服务器,和应用程序服务器.其中管理服务器提供了JNDI,安全,资源管理等基础服务,而应用程序服务器提供了Web容器,EJB容器,JMS容器等实现容器.
goodchen8 2003-08-26
  • 打赏
  • 举报
回复
免费电影高速下载
http://free.dlmovie.net/movie/freemovie.asp?userid=zscsichen
shining_ljr 2003-08-26
  • 打赏
  • 举报
回复
to:goodchen8(goodchen_8)
你他吗神经病啊,老是帖广告连接干什么??
Leric 2003-08-21
  • 打赏
  • 举报
回复
关注
wei977 2003-08-21
  • 打赏
  • 举报
回复
我真的很想写给你,但是我没有时间啊................

2,633

社区成员

发帖
与我相关
我的任务
社区描述
WebSphere 是 IBM 的软件平台。它包含了编写、运行和监视全天候的工业强度的随需应变 Web 应用程序和跨平台、跨产品解决方案所需要的整个中间件基础设施,如服务器、服务和工具。
社区管理员
  • WebSphere社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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