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

📄 signonejb.java

📁 学生注册— 本模块允许新的学生创建和维护他们的帐户信息
💻 JAVA
字号:
package day21ex.signon;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;

import day21ex.user.*;
import day21ex.student.*;

public class SignOnEJB implements SessionBean  {
   private SessionContext ctx;
   private HashSet cart;
   InitialContext initCtx = null;
   public SignOnEJB() {
      print("The container created this instance.\n");
   }
   public void setSessionContext(SessionContext ctx) {
      print("The container called the setSessionContext method ");
      print("to associate session bean instance with its context.\n");
      this.ctx = ctx;
   }
   public void ejbCreate() throws CreateException {
      print("The container called the ejbCreate method.\n");
      cart = new HashSet();
   }
   public void ejbActivate() {
      print("This instance has just been reactivated.\n");
   }
   public void ejbPassivate() {
      print("The container intends to passivate the instance.\n");
   }
   public void ejbRemove() {
      print("This instance is in the process of being removed ");
      print("by the container.\n");
   }

   public void addUser(String userName, String password){
      try {
         InitialContext ic = new InitialContext();
         UserLocalHome ulh = (UserLocalHome) ic.lookup("day21ex/User");
         UserLocal user = ulh.create(userName, password);
      } catch (Exception e) {
         throw new EJBException("Exception while adding user: " 
                                    + e.getMessage());
      }
   }
   public boolean validateUser(String userName, String password) 
      throws InvalidLoginException {
      try {
         InitialContext ic = new InitialContext();
         UserLocalHome ulh = (UserLocalHome) ic.lookup("day21ex/User");
         UserLocal user = ulh.findByPrimaryKey(userName);
         if (user == null) {
            throw new InvalidLoginException("Invalid login");
         }
         return user.matchPassword(password);
      } catch (FinderException fe) {
         throw new InvalidLoginException("Invalid login");
      } catch (NamingException ne) {
         throw new EJBException("Naming exception:" + ne.getMessage());
      }
   }
   
   void print(String s) {
      System.out.println("SignOnEJB:" + s);
   }
}

⌨️ 快捷键说明

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