JSP中带条件的查询分页

[b]对于带条件查询的分页,用到的主要是session,在提交时判断是不是第一次提交,如果是session.getAttribute("condition") ==null 则为空,同时创建一个新的这里我们用Map 存放健值对,并将此对象的放入session。
前面我们可以这样写
<fieldset>
<legend>物料搜索</legend>
<form action="GoodsAction?type=selectSome" method="post">
物料名字:<input type="text" name='goodsName' value="${condition['goodsName']} " />
物料类型<input type="text" name="goodsType" value="${condition['goodsType'] }"/><br/>
<input type="submit"/>
<hr/>
</form>
</fieldset>
<table border=1>
<tr>
<th>名字</th>
<th>数量</th>
<th>价格</th>
<th>类型</th>
<th>供应商</th>
</tr>
<c:forEach var ="temp" items="${page.list}">
<tr>
<td>${temp.name }</td>
<td>${temp.count }</td>
<td>${temp.price }</td>
<td>${temp.type_id }</td>
<td>${temp.provider_id}</td>
</tr>
</c:forEach>
</table>
<jsp:include page="../page.jsp">
<jsp:param value="GoodsAction" name="name"/>
<jsp:param value="selectSome" name="type"/>
</jsp:include>
---------------------------
后台
String pageNum = request.getParameter("pageNum");
String goodsName = request.getParameter("goodsName");
String goodsType = request.getParameter("goodsType");

HttpSession session = request.getSession();
Map<String, String> condition = (Map<String, String>) session.getAttribute("condition");
if (condition == null) {
condition = new HashMap<String, String>();
session.setAttribute("condition", condition);
}
if (goodsName != null) {
condition.put("goodsName", goodsName);
}
if (goodsType != null) {
condition.put("goodsType", goodsType);
}
if (pageNum == null)
pageNum = "1";

PageInfo p = new PageInfo(Integer.parseInt(pageNum), 10, "t_s_goods");
dao.getAll(p, condition);
request.setAttribute("page", p);
request.getRequestDispatcher("goods/goods_list.jsp").forward(request,response);[/b][code="java"]
[/code]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值