在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}