yuypuyang 2016-06-06 03:40 采纳率: 0%
浏览 634

在foreach下拉列表中,选中一个字段进行查找(字段对应多个值)。


在foreach下拉列表中,选中一个字段进行查找(字段对应多个值)。找到后怎样用foreach遍历出来??******

一,

根据 传入的cellphone值在数据库中的进行查找:

public List selectBycell(String cellphone) {
if(cellphone==null)
throw new IllegalArgumentException();

    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    List<Customer> cs= new ArrayList<Customer>();
    try{
        conn=JdbcUtil.getConnection();
        stmt = conn.prepareStatement("select id,name,gender,birthday,cellphone,email,hobby,type,description from customer where cellphone=?");
        stmt.setString(1,cellphone);
        rs = stmt.executeQuery();
        while(rs.next()){
            Customer c = new Customer();
            c.setId(rs.getString("id"));
            c.setName(rs.getString("name"));
            c.setGender(rs.getString("gender"));
            c.setBirthday(rs.getDate("birthday"));
            c.setCellphone(rs.getString("cellphone"));
            c.setEmail(rs.getString("email"));
            c.setHobby(rs.getString("hobby"));
            c.setType(rs.getString("type"));
            c.setDescription(rs.getString("description"));
            cs.add(c);
        }
        return cs;
     }catch(Exception e){
        throw new DaoException(e);

    }finally{
        JdbcUtil.release(rs, stmt, conn);

    }
}

}

二、servlet中的的方法

private void selectcell(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {

    String selecbyell =request.getParameter("cellphone");

     cs.selectByCell(selecbyell);
request.setAttribute("selecbyell", selecbyell);
request.getRequestDispatcher("/selectcustomer.jsp").forward(request, response);

}

三、在foreach中动态获取的下拉列表中,选中一个字段进行查找,这个字段可以对应多个值

==按电话查询==${cell}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?