首页 新闻 会员 周边

在foreach中动态获取的下拉列表中,选中一个字段进行查找,(这个字段可以对应多个值)。找到后怎样用foreach遍历出来

0
[待解决问题]

一,

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

public List<Customer> 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中动态获取的下拉列表中,选中一个字段进行查找,这个字段可以对应多个值

<form method="post" action="${pageContext.request.contextPath}/servlet/SelectBycell?operation=selectcell">
                    <select name="cellphone" id="cell" align="center">
                        <option value="">==按电话查询==</option>
                        <c:forEach items="${cellphone}" var="cell" varStatus="vs">
                            <option value="${cell}"><span align="center">${cell}</span></option>
                        </c:forEach>
                    </select>
                        <input type="image" id="submit" src="<c:url value='/images/select1.png'/>" class="loginBtn"/>
                </form>

小沐沐的木屋的主页 小沐沐的木屋 | 菜鸟二级 | 园豆:202
提问于:2016-06-06 11:32
< >
分享
所有回答(2)
0

select的onchange事件。选中时js调用查询方法、查询后list返回页面。遍历循环即可

Ctrl` | 园豆:3317 (老鸟四级) | 2016-06-06 11:54

多谢了

支持(0) 反对(0) 小沐沐的木屋 | 园豆:202 (菜鸟二级) | 2016-06-06 14:24
0

你把多个值在查询时变成集合,就可以foreach啦。

长蘑菇星人 | 园豆:1832 (小虾三级) | 2016-06-06 11:54

多谢了 ,已经弄出来了

 

支持(0) 反对(0) 小沐沐的木屋 | 园豆:202 (菜鸟二级) | 2016-06-06 14:23
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册