list all = new ArrayList(得到的collection)

解决方案 »

  1.   

    Iterator it = home.findAll().iterator();
    while(it.hasNext()) {
       remote = (EJBRemote)it.next();
       System.out.println(remote.getId());
    }
    这是我写的测试程序,希望能给你点启发
      

  2.   

    得到的結果為什麼是:
    user.ejb.userEJB_25585_EOImp1_WLStub@5c414db1
    user.ejb.userEJB_25585_EOImp1_WLStub@9c8417cf
    user.ejb.userEJB_25585_EOImp1_WLStub@8a1623bc
    user.ejb.userEJB_25585_EOImp1_WLStub@7c41776b
    user.ejb.userEJB_25585_EOImp1_WLStub@5c5b8651
    ejb class:
    public Collection ejbFindAll() throws RemoteException
    {
        Collection result;
        try{
           result=finduser();
         }catch(Exception ex){
           throw new EJBException("fail");
         }}private Collection finduser() throws SQLException
    {
        String str="select name from table1";
        PreparedStatement ps=con.prepareStatement(str);
        try{
             ResultSet rs=ps.executeQuery();
             ArrayList al=new ArrayList();
             while(rs.next()){
                  String name=rs.getString(1);
                  al.add(name);
              }
              return al;
           }finally{
              ps.close();
           }
    }
      

  3.   

    忘记告诉你要用remote.getId().toString(),否则都是句柄
      

  4.   

    String name=(String)rs.getString(1);
      

  5.   

    不对,是因为Collection里的元素是Object
      

  6.   

    diaopeng(遥远) 我用你是測試得到的都是null, 用ArrayList得到以上句柄
      

  7.   

    假设你的EJB的远程接口是User
    java.util.Collection c=home.findAll();
    User[] users=new User[c.size()];
    c.toArray(users);users就是你找到的所有远程对象
      

  8.   

    偶也才学,不知对否?<% page language = "java" %>
    <% import = "users.*,database.*,java.util.*" %>
    <%
    UserWeb userWeb = new UserWeb();
    AllayList arrayList = new AllayList();
    try{
    arrayList = userWeb.getAllUser();
    }
    catch(Exception e){
    out.println(e.getMessage());
    }
    %>
    <html>
    <head><title>全部注册用户:</title></head>
    <body>
    <center>
    <table border = "1">
    <tr>
    <td>账号</td>
    <td>名称</td>
    <td>Email</td>
    <td>删除</td>
    </tr>
    <tr>
    <%
    Iterator i = arrayList.itertor();
    while(i.hasnext()){
    UserModel userModel = (UserModel)i.next();
    %>
    <td><% = userModel.getUserID() %></td>
    <td><% = userModel.getUserName() %></td>
    <td><% = userModel.getUserEmail() %></td>
    <td><a herf = "deleteuser.jsp?userid = <% =userModel.getUserID() %>">删除</td>
    </tr>
    <%
    }
    %>
    </table>
    </center>
    </body>
    </html>