在java语言中,怎么用jsp的c标签进分页查询
如:<divid="pages"><ahref="#">上一页</a><c:forEachbegin="1"end="${rowsPerPage}"var="p"><c:...
如:
<div id="pages">
<a href="#">上一页</a>
<c:forEach begin="1" end="${rowsPerPage}" var="p">
<c:choose>
<c:when test="${p==page}">
<a href="#" class="current_page">${p}</a>
</c:when>
<c:otherwise>
<a href="cost.action?page=${p}">${p}</a>
</c:otherwise>
</c:choose>
</c:forEach>
<a href="#">下一页</a>
</div>
</form>
上一页 上一页 下一页 下一页
按1,2..这样的数字可以查询. 问题就是不知道,下一页或上页这里面怎么写,可以点击查询分页 展开
<div id="pages">
<a href="#">上一页</a>
<c:forEach begin="1" end="${rowsPerPage}" var="p">
<c:choose>
<c:when test="${p==page}">
<a href="#" class="current_page">${p}</a>
</c:when>
<c:otherwise>
<a href="cost.action?page=${p}">${p}</a>
</c:otherwise>
</c:choose>
</c:forEach>
<a href="#">下一页</a>
</div>
</form>
上一页 上一页 下一页 下一页
按1,2..这样的数字可以查询. 问题就是不知道,下一页或上页这里面怎么写,可以点击查询分页 展开
2015-12-17 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
jsp用c标签实现分页的方式如下:
<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ attribute name="curIndex" type="java.lang.Long" required="true"%>
<%@ attribute name="pageSize" type="java.lang.Long" required="true"%>
<%@ attribute name="pagerRange" type="java.lang.Long" required="true"%>
<%@ attribute name="totalPage" type="java.lang.Long" required="true"%>
<%@ attribute name="formId" type="java.lang.String" required="true"%>
<%
long begin = Math.max(1, curIndex - pagerRange/2);
long end = Math.min(begin + (pagerRange-1),totalPage);
request.setAttribute("p_begin", begin);
request.setAttribute("p_end", end);
%>
<table class="pager">
<tr>
<% if (curIndex!=1){%>
<td><a href="javascript:gotoPage(1)">首页</a></td>
<td><a href="javascript:gotoPage(<%=curIndex-1%>)">上一页</a></td>
<%}else{%>
<td class="disabled"><a href="#">首页</a></td>
<td class="disabled"><a href="#">上一页</a></td>
<%}%>
<c:forEach var="i" begin="${p_begin}" end="${p_end}">
<c:choose>
<c:when test="${i == curIndex}">
<td class="active"><a href="#">${i}</a></td>
</c:when>
<c:otherwise>
<td><a href="javascript:gotoPage(${i})">${i}</a></td>
</c:otherwise>
</c:choose>
</c:forEach>
<% if (curIndex!=totalPage){%>
<td><a href="#">下一页</a></td>
<td><a href="#">末页</a></td>
<%}else{%>
<td class="disabled"><a href="javascript:gotoPage(<%=curIndex+1%>)">下一页</a></td>
<td class="disabled"><a href="javascript:gotoPage(<%=totalPage%>)">末页</a></td>
<%}%>
<td><a>共${totalPage}页</a></td>
<td class="input_li">跳转到:<input type="text" id="p_pageIndex" size="2" value="<c:out value="${pageIndex}"/>"/>页 <input type="button" id="gotoBtn" onclick="gotoPageByBtn()" value="GO"/></td>
<td class="input_li"> 每页:
<select id="p_pageSizeSelect" onchange="gotoPage(<%=curIndex%>)">
<option value="10" <c:if test="${pageSize==10}">selected</c:if>>10条</option>
<option value="20" <c:if test="${pageSize==20}">selected</c:if>>20条</option>
<option value="50" <c:if test="${pageSize==50}">selected</c:if>>50条</option>
</select>
</td>
</tr>
</table>
控制分页的代码如下
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="tags"%>
<head>
<style><!--分页样式-->
.pager { font: 12px Arial, Helvetica, sans-serif;}
.pager a {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;margin-right:2px;line-height:30px;vertical-align:middle;}
.pager .active a{color:red;border:none;}
.pager a:visited {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.pager a:hover {color: #fff; background: #ffa501;border-color:#ffa501;text-decoration: none;}
.pager .input_li{padding: 1px 6px;}
</style>
<script><!--分页跳转脚本-->
function gotoPage(pageIndex){
var queryForm = document.getElementById("queryForm");
var action = queryForm.action;
var pageSize = document.getElementById("p_pageSizeSelect").value;
action += "?pageIndex=" + pageIndex + "&pageSize=" + pageSize;
//alert(action);
queryForm.action = action;
queryForm.submit();
}
function gotoPageByBtn(){
var pageIndex = document.getElementById("p_pageIndex").value;
var pageIndexInt = parseInt(pageIndex);
var totalPage = ${totalPage};
if(pageIndexInt>0 && pageIndexInt<totalPage){
gotoPage(pageIndex);
}
else{
alert("输入页数超出范围!");
}
}
</script>
</head>
<body>
<form id="queryForm" action="${basePath}/log/list" method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="userName" value="<c:out value="${userName}"/>"/> </td>
<td><input type="submit" text="查询"/></td>
</tr>
</table>
</form>
<tags:pager pagerRange="10" pageSize="${pageSize}" totalPage="${totalPage}" curIndex="${pageIndex}" formId="queryForm"></tags:pager>
<table class="border">
<thead>
<tr>
<th width="100">用户名称</th>
<th width="500">操作内容</th>
<th width="200">操作时间</th>
</tr>
</thead>
<tbody>
<c:forEach items="${logList}" var="log">
<tr>
<td>${log.userName}</td>
<td>${log.result}</td>
<td>
<fmt:formatDate value="${log.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
</td>
</tr>
</c:forEach>
</tbody>
</table>
<tags:pager pagerRange="10" pageSize="${pageSize}" totalPage="${totalPage}" curIndex="${pageIndex}" formId="queryForm"></tags:pager>
</body>
<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ attribute name="curIndex" type="java.lang.Long" required="true"%>
<%@ attribute name="pageSize" type="java.lang.Long" required="true"%>
<%@ attribute name="pagerRange" type="java.lang.Long" required="true"%>
<%@ attribute name="totalPage" type="java.lang.Long" required="true"%>
<%@ attribute name="formId" type="java.lang.String" required="true"%>
<%
long begin = Math.max(1, curIndex - pagerRange/2);
long end = Math.min(begin + (pagerRange-1),totalPage);
request.setAttribute("p_begin", begin);
request.setAttribute("p_end", end);
%>
<table class="pager">
<tr>
<% if (curIndex!=1){%>
<td><a href="javascript:gotoPage(1)">首页</a></td>
<td><a href="javascript:gotoPage(<%=curIndex-1%>)">上一页</a></td>
<%}else{%>
<td class="disabled"><a href="#">首页</a></td>
<td class="disabled"><a href="#">上一页</a></td>
<%}%>
<c:forEach var="i" begin="${p_begin}" end="${p_end}">
<c:choose>
<c:when test="${i == curIndex}">
<td class="active"><a href="#">${i}</a></td>
</c:when>
<c:otherwise>
<td><a href="javascript:gotoPage(${i})">${i}</a></td>
</c:otherwise>
</c:choose>
</c:forEach>
<% if (curIndex!=totalPage){%>
<td><a href="#">下一页</a></td>
<td><a href="#">末页</a></td>
<%}else{%>
<td class="disabled"><a href="javascript:gotoPage(<%=curIndex+1%>)">下一页</a></td>
<td class="disabled"><a href="javascript:gotoPage(<%=totalPage%>)">末页</a></td>
<%}%>
<td><a>共${totalPage}页</a></td>
<td class="input_li">跳转到:<input type="text" id="p_pageIndex" size="2" value="<c:out value="${pageIndex}"/>"/>页 <input type="button" id="gotoBtn" onclick="gotoPageByBtn()" value="GO"/></td>
<td class="input_li"> 每页:
<select id="p_pageSizeSelect" onchange="gotoPage(<%=curIndex%>)">
<option value="10" <c:if test="${pageSize==10}">selected</c:if>>10条</option>
<option value="20" <c:if test="${pageSize==20}">selected</c:if>>20条</option>
<option value="50" <c:if test="${pageSize==50}">selected</c:if>>50条</option>
</select>
</td>
</tr>
</table>
控制分页的代码如下
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="tags"%>
<head>
<style><!--分页样式-->
.pager { font: 12px Arial, Helvetica, sans-serif;}
.pager a {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;margin-right:2px;line-height:30px;vertical-align:middle;}
.pager .active a{color:red;border:none;}
.pager a:visited {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.pager a:hover {color: #fff; background: #ffa501;border-color:#ffa501;text-decoration: none;}
.pager .input_li{padding: 1px 6px;}
</style>
<script><!--分页跳转脚本-->
function gotoPage(pageIndex){
var queryForm = document.getElementById("queryForm");
var action = queryForm.action;
var pageSize = document.getElementById("p_pageSizeSelect").value;
action += "?pageIndex=" + pageIndex + "&pageSize=" + pageSize;
//alert(action);
queryForm.action = action;
queryForm.submit();
}
function gotoPageByBtn(){
var pageIndex = document.getElementById("p_pageIndex").value;
var pageIndexInt = parseInt(pageIndex);
var totalPage = ${totalPage};
if(pageIndexInt>0 && pageIndexInt<totalPage){
gotoPage(pageIndex);
}
else{
alert("输入页数超出范围!");
}
}
</script>
</head>
<body>
<form id="queryForm" action="${basePath}/log/list" method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="userName" value="<c:out value="${userName}"/>"/> </td>
<td><input type="submit" text="查询"/></td>
</tr>
</table>
</form>
<tags:pager pagerRange="10" pageSize="${pageSize}" totalPage="${totalPage}" curIndex="${pageIndex}" formId="queryForm"></tags:pager>
<table class="border">
<thead>
<tr>
<th width="100">用户名称</th>
<th width="500">操作内容</th>
<th width="200">操作时间</th>
</tr>
</thead>
<tbody>
<c:forEach items="${logList}" var="log">
<tr>
<td>${log.userName}</td>
<td>${log.result}</td>
<td>
<fmt:formatDate value="${log.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
</td>
</tr>
</c:forEach>
</tbody>
</table>
<tags:pager pagerRange="10" pageSize="${pageSize}" totalPage="${totalPage}" curIndex="${pageIndex}" formId="queryForm"></tags:pager>
</body>
推荐于2016-07-11
展开全部
<a href=".....action?pageIndex=1">首页</a>
<a href=".....action?pageIndex=${currentPage>1?currentPage-1:1}">上一页</a>
<a href=".......action?pageIndex=${currentPage<totalPage?currentPage+1:totalPage}">下一页</a>
<a href=".......action?pageIndex=${totalPage}">末页</a>
<a href=".....action?pageIndex=${currentPage>1?currentPage-1:1}">上一页</a>
<a href=".......action?pageIndex=${currentPage<totalPage?currentPage+1:totalPage}">下一页</a>
<a href=".......action?pageIndex=${totalPage}">末页</a>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你试试在循环上面加上<c:set>起一个变量去保存当前页数,然后加就是+1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询