⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginbean.java~62~

📁 一个四层结构的j2ee项目实例。对于初学者相当合适。欢迎下载使用。
💻 JAVA~62~
字号:
package sqlaccounts;import javax.ejb.*;import javax.naming.*;import javax.rmi.PortableRemoteObject;import java.rmi.RemoteException;import java.util.Collection;import java.util.Hashtable;import java.util.Properties;import java.util.Vector;import java.util.Iterator;import javax.ejb.CreateException;import javax.ejb.DuplicateKeyException;import javax.ejb.FinderException;import javax.ejb.ObjectNotFoundException;import javax.ejb.RemoveException;import javax.naming.Context;import javax.naming.InitialContext;import javax.naming.NamingException;import javax.rmi.PortableRemoteObject;public class LoginBean implements SessionBean {  SessionContext sessionContext;  private EjbAccountsHome ejbAccountsHome = null;  private EjbAccounts  ejbAccounts=null;  //管理日志变量  private AManagerLogHome aManagerLogHome = null;  private AManagerLog  aManagerLog=null;  public  Collection   conType;  java.lang.String type;  //String Type;  public   LoginBean()  {  }  public   LoginBean(String Type)  {    this.type=Type;  }public void ejbCreate() throws CreateException {    /**@todo Complete this method*/    try    {        Context ctx = new InitialContext();        Object ref = ctx.lookup("EjbAccountsRemote");        //this.employeeHome = (EmployeeRemoteHome)PortableRemoteObject.narrow(ctx.lookup("EmployeeRemote"),EmployeeRemoteHome.class);        this.ejbAccountsHome = (EjbAccountsHome)PortableRemoteObject.narrow(ref,EjbAccountsHome.class);        // EjbAccounts ejbAccounts = ejbAccountsHome.findByPrimaryKey(Id);    }    catch(Exception e){    }}  public void ejbRemove() {    /**@todo Complete this method*/  }  public void ejbActivate() {    /**@todo Complete this method*/  }  public void ejbPassivate() {    /**@todo Complete this method*/  }  public void setSessionContext(SessionContext sessionContext) {    this.sessionContext = sessionContext;  }  public boolean login(String Id) {    /**@todo Complete this method*/    try{       //Context ctx = new InitialContext();       //Object ref = ctx.lookup("EjbAccountsRemote");      //this.employeeHome = (EmployeeRemoteHome)PortableRemoteObject.narrow(ctx.lookup("EmployeeRemote"),EmployeeRemoteHome.class);      //this.ejbAccountsHome = (EjbAccountsHome)PortableRemoteObject.narrow(ref,EjbAccountsHome.class);       ejbAccounts = ejbAccountsHome.findByPrimaryKey(Id);    }catch(Exception e){      log("不能找到用户ID号码!");      return false;    }    log("找到用户ID号码!");    return true;  }  private void log(String s) {   System.out.println(s);  }  public boolean AddId(String id, String Type, double bal)  {    /**@todo Complete this method*/    long startTime = 0;    try    {      ejbAccounts = ejbAccountsHome.create(id, Type, bal);    }    catch(Exception e)    {      log("Failed: create(" + id + ", " + Type + ", " + bal + ")");      return false;    }     log("成功创建账号:(" + id + ", " + Type + ", " + bal + ")");    return true;  }  //发现和创建账号  public boolean findOrCreateAccount(String id, String accountType, double balance)  {   try {     ejbAccounts =ejbAccountsHome.findByPrimaryKey(id);//(EjbAccounts)PortableRemoteObject.narrow(ejbAccountsHome.findByPrimaryKey(id), EjbAccounts.class);      log("发现新账号:(" + id + ", " + accountType + ", " + balance + ")");      ejbAccounts.remove();      log("删除新账号:(" + id + ", " + accountType + ", " + balance + ")");      return true;   }   catch (Exception onfe)   {     // the account id does not yet exist so create it.     if(AddId(id, accountType, balance)==true)       //ejbAccounts = ejbAccountsHome.create(id, accountType, balance);     {       log("创建新账号:(" + id + ", " + accountType + ", " + balance + ")");       return false;     }     else       return false;   }  }  public Vector findByType(String Type)  {        try        {        Collection AllejbAccounts = ejbAccountsHome.findByType(Type);        if (AllejbAccounts.isEmpty())          return null;        Iterator it = AllejbAccounts.iterator();        Vector all=new Vector();        while (it.hasNext()){         /* EjbAccounts ejbAccounts = (EjbAccounts)(javax.rmi.PortableRemoteObject.narrow(it.next(),EjbAccounts.class));          Login x=GetLogintype(ejbAccounts.getType());            //all.add(new LoginBean(ejbAccounts.getType()));          all.add(x);            */            EjbAccounts ejbAccounts = (EjbAccounts)(javax.rmi.PortableRemoteObject.narrow(it.next(),EjbAccounts.class));            String[] info ={ejbAccounts.getType().toString(),""+ejbAccounts.getBal(),toString(),""+ejbAccounts.getId(),};            all.add(info);        }         return all;        }catch(Exception e){        return null;        }  }    public Login GetLogintype(String type)    {        /**@todo Complete this method*/        setType(type);       // Login loginBean=new Login();       // loginBean.setType(type);        //return loginBean;        return null;    }    public void untitledMethod1()    {        /**@todo Complete this method*/    }    //查出所有的认证日志    public Vector findAllManagelog()    {        /**@todo Complete this method*/        try        {        Collection AllManagelog = aManagerLogHome.findAllManagelog();        if (AllManagelog.isEmpty())          return null;        Iterator it = AllManagelog.iterator();        Vector all=new Vector();        while (it.hasNext()){            AManagerLog aManagerLog = (AManagerLog)(javax.rmi.PortableRemoteObject.narrow(it.next(),AManagerLog.class));            String[] info ={ejbAccounts.getType().toString(),""+ejbAccounts.getBal(),toString(),""+ejbAccounts.getId(),};            all.add(info);        }         return all;        }catch(Exception e){        return null;        }    }  public void setType(java.lang.String type)  {        this.type = type;  }  public java.lang.String getType()  {        return type;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -