那位给小弟写个调用HelloBean的客户端(jsp)的。
小弟写了一个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)的。