我只知道用arraylist封装到javabean然后进行传值,但具体怎么做,谁能给我写写?

解决方案 »

  1.   

    举例,如果结果有三个字段,ID,Name和Value,class Item {
        int id;
        String name;
        String value;
    }遍历ResultSet,取出每一条结果,生成新的 Item对象
    ArrayList result;
    while (rs.next()) {
        Item item = new Item;
        item.id = rs.getInt("id");
        item.name = rs.getString("name");
        item.value = rs.getString("value");
        result.add(item);
    }这个result就是你要的东西。如果你是写的JSP,可以不需要先生成ArrayList,直接在While循环体内将HTML输出就行
      

  2.   

    ArrayList list = new ArrayList();
    UserBean userbean = null;
    while(rs.next()){
    userbean = new UserBean();
    userbean.setName = rs.getString(1);
    .
    .
    .
    list.add(userbean);
    }
    return list;在servlet接收返回的list,再session.setAttribute("list",list);再forward定向到jsp页面session.getAttribute("list")
    就可以得到数据库的记录了。
      

  3.   

    不错不错~!第二位把在JSP上的也说了