jsp多条件查询,谁有完整的小项目,发给我一个,纠结中、或者帮忙看下哪儿出错了
<%//获取搜索框中的值Stringsearchname=request.getParameter("search");//获取省Stringprovince=reque...
<%
//获取搜索框中的值
String searchname=request.getParameter("search");
//获取省
String province=request.getParameter("s_province");
//获取市
String city=request.getParameter("s_city");
//获取县
String county=request.getParameter("s_county");
//获取下拉框中的值
String users=request.getParameter("users");
//连接数据库 进行搜索查询
Connection conn=null;
PreparedStatement pst=null;
ResultSet rst=null;
Store store=new Store();
List<Store> list=new ArrayList<Store>();
conn=HelpDB.getConnection();
pst=conn.prepareStatement("select name,remark from store where name like '%?%' and sheng like '%?%' and shi like '%?%' and xian like '%?%'");
pst.setString(1,searchname);
pst.setString(2,province);
pst.setString(3,city);
pst.setString(4,county);
rst=pst.executeQuery();
while(rst.next()){
store.setName(rst.getString(1));
store.setRemark(rst.getString(2));
list.add(store);
}
//request.setAttribute(list);
response.sendRedirect("/jiagebaike/result/searchshops.jsp");
%>
searchshops.jsp页面
<c:forEach var="maile" items="${list}" varStatus="num">
<div><a href="#">${maile.name}</a></div>
<div>${maile.remark}</div><br />
</c:forEach> 展开
//获取搜索框中的值
String searchname=request.getParameter("search");
//获取省
String province=request.getParameter("s_province");
//获取市
String city=request.getParameter("s_city");
//获取县
String county=request.getParameter("s_county");
//获取下拉框中的值
String users=request.getParameter("users");
//连接数据库 进行搜索查询
Connection conn=null;
PreparedStatement pst=null;
ResultSet rst=null;
Store store=new Store();
List<Store> list=new ArrayList<Store>();
conn=HelpDB.getConnection();
pst=conn.prepareStatement("select name,remark from store where name like '%?%' and sheng like '%?%' and shi like '%?%' and xian like '%?%'");
pst.setString(1,searchname);
pst.setString(2,province);
pst.setString(3,city);
pst.setString(4,county);
rst=pst.executeQuery();
while(rst.next()){
store.setName(rst.getString(1));
store.setRemark(rst.getString(2));
list.add(store);
}
//request.setAttribute(list);
response.sendRedirect("/jiagebaike/result/searchshops.jsp");
%>
searchshops.jsp页面
<c:forEach var="maile" items="${list}" varStatus="num">
<div><a href="#">${maile.name}</a></div>
<div>${maile.remark}</div><br />
</c:forEach> 展开
展开全部
while(rst.next()){
Store store=new Store();//把之前的这条语句放在这里
store.setName(rst.getString(1));
store.setRemark(rst.getString(2));
list.add(store);
}
每条记录应该是一个Store对象,你那样写实际上是一个对象保存一条数据,rs.next之后继续用同一个Store来保存 所以是最后一个.
Store store=new Store();//把之前的这条语句放在这里
store.setName(rst.getString(1));
store.setRemark(rst.getString(2));
list.add(store);
}
每条记录应该是一个Store对象,你那样写实际上是一个对象保存一条数据,rs.next之后继续用同一个Store来保存 所以是最后一个.
追问
~~~~(>_<)~~~~ 还是不对啊、、
追答
//request.setAttribute(list);
response.sendRedirect("/jiagebaike/result/searchshops.jsp");
把这两行代码修改为
request.setAttribute(list);
request.getRequestDispatcher("/jiagebaike/result/searchshops.jsp").forward(request,response);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询