[1][2][3]4[5][6][7][8][9] 當前頁curPage 頁總數pageCount 顯示標簽數showCount = 9 開始start = curPage -4 >= 1 ?curPage - 4 : 1 結束end = curPage +4 <= pageCount? curPage + 4:pageCount for(int i=start; i<end+1; i++){ %><a href="...">I</a><% } www.2cto.com PageUtilImpl apage = (PageUtilImpl)request.getAttribute("page"); long curPage = apage.getCurPage(); long pageCount = apage.getPageCount(); long start = curPage - 4 > 1 ? curPage - 4 : 1; long end = curPage +4 <= pageCount ? curPage + 4 : pageCount; for(long i = start; i <= end; i++){ if(i == curPage)out.print(i); else{%> <a href="${theURL}${mark}page.toPage=<%=i%>${para}">[<%=i%>]</a> <%} }