<%@ page contentType="text/html; charset=gb2312" buffer="none"%><br /><%@ page import="java.util.*"%><br /><%<br />//初始化全域變數<br /> int totalNum = 6; //總共記錄條數<br /> int numPerPage = 2; //每頁顯示記錄條數<br /> int maxPageNum = 0; //本次搜尋最大頁數<br /> int curPage = 1; //當前頁<br /> int startLocation = 0; //起始位置</p><p> // Vector searchresult = (Vector) session.getAttribute("searchresult");<br /> Vector searchresult = new Vector();<br /> searchresult.add(0,String.valueOf(0));<br /> searchresult.add(1,String.valueOf(1));<br /> searchresult.add(2,String.valueOf(2));<br /> searchresult.add(3,String.valueOf(3));<br /> searchresult.add(4,String.valueOf(4));<br /> searchresult.add(5,String.valueOf(5));<br /> // numPerPage = ((Integer)session.getAttribute("setPageNum")).intValue();<br /> //totalNum = searchresult.size();<br /> maxPageNum=((totalNum%numPerPage) == 0)?totalNum/numPerPage:(totalNum/numPerPage+1);<br /> curPage=startLocation/numPerPage + 1;</p><p>%><br /><html><br /> <head><br /><META http-equiv=Content-Type content="text/html; charset=gb2312"><br /> <title>查詢結果頁面</title><br /> <STYLE><br /> BODY { MARGIN: 6px 0px 0px; COLOR: #000; BACKGROUND-COLOR: #fff; FONT-FAMILY: arial }<br /> TABLE { BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px }<br /> TD { FONT-SIZE: 11pt; LINE-HEIGHT: 18px; FONT-FAMILY: arial; text-align:center}<br /> .p { PADDING-LEFT: 18px; FONT-SIZE: 14px; WORD-SPACING: 4px }<br /> #ft { CLEAR: both; BACKGROUND: #e6e6e6; LINE-HEIGHT: 20px; TEXT-ALIGN: center; FONT-SIZE: 12px; COLOR: #77c; FONT-FAMILY: Arial }<br /> </STYLE><br /></head><br /><%</p><p> if(request.getParameter("startLocation")!=null)<br /> {<br /> startLocation = Integer.parseInt(request.getParameter("startLocation")); //取當前頁碼<br /> System.out.println("startLocation ="+startLocation);<br /> curPage = ((startLocation%numPerPage) == 0)?(startLocation/numPerPage):(startLocation/numPerPage+1);<br /> curPage=curPage+1;<br /> System.out.println("curPage ="+curPage);<br /> }</p><p>%><br /><body><br /><form method="POST" ><br /> <table border="0.5" width="100%" ><br /> <tr bgcolor="#72963D"><br /> <td align="center" class="colsTitle" nowrap height="19"><br /> 查詢結果<br /> </td><br /> </tr><br /> <%<br /> if(curPage<maxPageNum){<br /> System.out.println("startLocation="+startLocation);<br /> for(int i=startLocation; i<startLocation+numPerPage; i++){<br /> String result = (String) searchresult.elementAt(i);<br /> out.println("<tr bgcolor=/"#F1F0ED/">");<br /> out.println("<td align=/"center/" nowrap height=/"19/">");<br /> out.println(result);<br /> out.println("</td>");<br /> out.println("</tr>");<br /> }<br /> }else{<br /> System.out.println("totalNum="+totalNum);<br /> for(int i=startLocation; i<totalNum; i++){<br /> String result = (String) searchresult.elementAt(i);<br /> out.println("<tr bgcolor=/"#F1F0ED/">");<br /> out.println("<td align=/"center/" nowrap height=/"19/">");<br /> out.println(result);<br /> out.println("</td>");<br /> out.println("</tr>");<br /> }<br /> }<br /> //searchresult.clear();<br /> %><br /> <tr><td><br /> <hr align="center" color="#990066" width="500"><br /> </td><br /> <tr><br /> <td><br /> <%<br /> if (curPage > 1 ) {<br /> out.println("<a href="MyJsp.jsp?startLocation="+(startLocation-numPerPage));<br /> out.println("" mce_href="MyJsp.jsp?startLocation="+(startLocation-numPerPage));<br /> out.println("">上一頁</a>");<br /> }<br /> if(maxPageNum > 10) {<br /> int totalNumShow = curPage + 9;<br /> int startLocationPage = 0;<br /> if( totalNumShow > maxPageNum) {<br /> totalNumShow = maxPageNum;<br /> }<br /> if( maxPageNum > 11 && curPage > 11) {<br /> startLocationPage = curPage - 11;<br /> }<br /> for(int i=startLocationPage;i<totalNumShow;i++) {<br /> if(i+1 == curPage) {<br /> %> [<%=i+1%>] <%<br /> } else {<br /> %><a href="MyJsp.jsp?startLocation=<%=i*numPerPage%>"> <%=i+1 %> </a><%<br /> }<br /> }<br /> }<br /> else {<br /> for( int i=0;i<maxPageNum;i++) {<br /> if( i+1 == curPage) {<br /> %> [<%=i+1 %>] <%<br /> } else {<br /> %><a href="MyJsp.jsp?startLocation=<%=i*numPerPage%>"> <%=i+1 %> </a><%<br /> }<br /> }<br /> }<br /> if ( curPage < maxPageNum) {<br /> out.println("<a href="MyJsp.jsp?startLocation="+(startLocation+numPerPage));<br /> out.println("" mce_href="MyJsp.jsp?startLocation="+(startLocation+numPerPage));<br /> out.println("">下一頁</a>");<br /> }<br /> %><br /> </td><br /> </tr></p><p> </table><br /> </form><br /></body><br /></html>