可以用一个session bean代理验证,比如session bean为SignOnEJB内有public boolean authenticate(String userName, String password)方法,这个方法调用实体bean UserBean中的findByPrimaryKey(String userName)(加入主键是userName)那么在UserBean这层是抛出FinderException,由于authenticate中调用的是类似于UserLocal user =UserBean的远程接口.findByPrimaryKey(userName);在这层上它会得到user=null,这样可继续处理,比如返回值为false,没通过怎么怎么样,通过了又怎么怎么样……
总之就是通过session bean过渡一下

解决方案 »

  1.   

    可是当找不到的时候它就会抛出notfinder异常而不是返回null
    =================================================================
    你可以findByName(String uname,String passwd)
    ejb ql::=select object(o) from user as o where o.uname=?1 and o.passwd = ?2
    内层catch ObjectNotFoundException,表明对象没有(也就是密码错误)
    外层catch FinderException ,系统异常。
      

  2.   

    ejb Finder做的很怪的地方就是:找不到数据的时候就抛出FinderException,
      

  3.   

    为什么ejbFinder不返回 null:
    我觉得是不是因为 ejbFinder找不到对象是因为Home无法定位相应的ejb,返回null是不适合的,因为这时候实例池里面有若干ejb对象,仅仅是他们无一例外的无法被正确定位罢了。
    个人猜测哦,错了不要见笑。
      

  4.   

    我用的是CMP我看系统自动生成的文件里判断
          if (__WL_pkMap.size() == 0) {
            if(__WL_verbose) {
              Debug.say("Throwing FinderException because bean wasn't found.");
            }
            throw new javax.ejb.ObjectNotFoundException("Bean not found in 'findByName'.");
          }
    你看,是系统自动向外抛的异常kofwr(搭补流二),您的意思是不是让我在SessionBean里面try啊。
      

  5.   

    public boolean checkUser(String username, String password) {
        try{
          javax.naming.Context ctx=new javax.naming.InitialContext();
         MyUserHome userhome=(MyUserHome)ctx.lookup("MyUser");
         MyUser user=userhome.findByName(username);
          if (user==null){
            return false;
          }
          if (!user.getUPassword().equals(password)){
            return false;
          }
         return true;
        }catch(Exception e){e.printStackTrace();}
        return true;
      }
    我的sessionbean就是这么写的。不对,他不会返回null