给你段代码
String name = form.getName().trim();
String pass = form.getPassword().trim();
String npass = "";
// 实体ejb的home 接口和 remote接口
UsernameRemoteHome home = null;
UsernameRemote remote = null;
try
{
Context ctx = new InitialContext();
home = (UsernameRemoteHome) ctx.lookup("UsernameRemote");
//调用实体ejb的方法
remote = home.findByName(name);
System.out.println("look up success");
}
catch(Exception ep)
{
System.out.println("look up fail");
return (actionMapping.findForward("fail"));
} //如果用户存在,取得其密码在进行比较
try
{
npass = remote.getPassword().trim();
System.out.println("find pass success");
}
catch(Exception ep)
{
System.out.println("find pass fail");
return (actionMapping.findForward("fail"));
}
//如果密码正确,转到界面
if (npass.equals(pass))
{
System.out.println("equel");
return (actionMapping.findForward("success")); }
else
{
System.out.println(npass);
System.out.println(pass);
System.out.println("not equel");
return (actionMapping.findForward("fail"));
}
String name = form.getName().trim();
String pass = form.getPassword().trim();
String npass = "";
// 实体ejb的home 接口和 remote接口
UsernameRemoteHome home = null;
UsernameRemote remote = null;
try
{
Context ctx = new InitialContext();
home = (UsernameRemoteHome) ctx.lookup("UsernameRemote");
//调用实体ejb的方法
remote = home.findByName(name);
System.out.println("look up success");
}
catch(Exception ep)
{
System.out.println("look up fail");
return (actionMapping.findForward("fail"));
} //如果用户存在,取得其密码在进行比较
try
{
npass = remote.getPassword().trim();
System.out.println("find pass success");
}
catch(Exception ep)
{
System.out.println("find pass fail");
return (actionMapping.findForward("fail"));
}
//如果密码正确,转到界面
if (npass.equals(pass))
{
System.out.println("equel");
return (actionMapping.findForward("success")); }
else
{
System.out.println(npass);
System.out.println(pass);
System.out.println("not equel");
return (actionMapping.findForward("fail"));
}
LeavewordFacadeHome home=(LeavewordFacadeHome)PortableRemoteObject.narrow(objref,LeavewordFacadeHome.class);
// 这是是将对象的类型进行转换
Object objRef=ctx.lookup("helloSessionbean");
helloSessionbeanHome home=(helloSessionbeanHome)javax.rmi.PortableRemoteObject.narrow(objRef,helloSessionbeanHome.class);
helloSessionbean hs=home.create();
String str=hs.helloEJB();
在session bean里面定义了方法public int add(){};//数据库新增方法servlet调用它的过程:
void add(){
testHome home = null;
test remote = null;
try{
Context ctx = new InitialContext();
home = (testHome) ctx.lookup("test");//这里的“test”就是jndi name,这一步用于获得获得远程接口
//调用session ejb的方法add()
remote = home.add();
System.out.println("look up success");
}
catch(Exception e){
System.out.println("look up fail");
}
}
特别是和html整合,读取数据方面的
初次访问通过JNDI查找。
这些可以举一反三的
一个例子够了