Jsp simple instance paging code
<%
Int pageSize = 10;
Int showPage = 1;
Int recCount = 0;
Int pageCount = 0;
String SqlArticle;
String toPage = request. getParameter ("page ");
SqlArticle = "Select * from hl_news where smallname = '" + csmallname + "'Order
Times DESC ";
ResultSet rsarticle1_stmt1.exe cuteQuery (SqlArticle );
If (RsArticle. next ()){
RsArticle. last ();
RecCount = RsArticle. getRow ();
PageCount = (recCount % pageSize) = 0? (RecCount/pageSize ):
(RecCount/pageSize) + 1 );
If (toPage! = Null)
ShowPage = Integer. parseInt (toPage );
RsArticle. absolute (showPage-1) * pageSize + 1 );
For (int I = 1; I <= pageSize; I ++ ){
Int NID = RsArticle. getInt ("ID ");
String ttt = RsArticle. getString ("times ");
%>
<Tr>
<Td align = "middle" width = "18">
Src = "images/kuang_10.gif" width = "5"/> </td>
<Td class = "riqi_1" align = "middle"
Width = "92"> <span class = "f-14-hui" style = "width: 100px;"> <% = ttt %> |
</Span> </td>
& Lt; td width = "463" height = "30" align = "left"
Class = "tong_1"> <a class = "wen_4" href = "newshows. jsp? Id = <% = NID %>"
Target = "_ blank"> <% = RsArticle. getString ("title") %> </a> </td>
<Td width = "56" class = "wen_4"> [<
Href = "newshows. jsp? Id = <% = NID %> "target =" _ blank "> View </a>] </td>
</Tr>
<Tr>
<Td background = "images/kuang_09.gif" colspan = "4"
Height = "2"> </td>
</Tr>
<%
If (! RsArticle. next ())
Break;
}
}
%>
</Tbody>
</Table> </td>
<Td width = "4"
Background = "images/kuang_05.gif"> </td>
</Tr>
<Tr>
<Td width = "4" height = "4"> Src = "images/kuang_06.gif"
Width = "4"/> </td>
<Td background = "images/kuang_07.gif"
Height = "4"> </td>
<Td width = "4" height = "4"> Src = "images/kuang_08.gif"
Width = "4"/> </td>
</Tr>
</Tbody>
</Table>
<Table align = "center" border = "0">
<Form onsubmit = "document. location =
'Http: // www.intgz.com/news.asp? Cid = 1 & amp; Page = '+ this. page. value; return
False; "method =" get ">
<Tbody>
<Tr>
<Td align = "right"> <% if (showPage> 1) {%> <a class = 'F
-12-black 'href = 'news. jsp? Id = <% = cid %> & smallname = <% = csmallname %> & page = 1'> First
Page </a> <%} if (showPage> 1) {%> <a class = 'F-12-black 'href = 'news. jsp? Id = <%
= Cid %> & smallname = <% = csmallname %> & page = <% = showPage-1 %> '> Previous page </a> & nbsp; <%
} If (showPage <pageCount) {%> & nbsp; <a class = 'F-12-black' href = 'news. jsp?
Id = <% = cid %> & smallname = <% = csmallname %> & page = <% = showPage + 1%> '> Next page
</A> & nbsp; <% }%> & nbsp; <% if (showPage <pageCount) {%> <a class = 'F-12-black'
Href = 'news. jsp? Id = <% = cid %> & smallname = <% = csmallname %> & page = <% = pageCount %> '>
Last page </a> & nbsp; <% }%>: <% = showPage %
>/<% = PageCount %> a total of <% = recCount %> records <a class = 'F-12-black'> are transferred
<Select name = 'sel _ page' onChange = 'javascript: location = this. options
[This. selectedIndex]. value; '> <% for (int I = 1; I <= pageCount; I ++) {%> <option
Value = 'news. jsp? Id = <% = cid %> & smallname = <% = csmallname %> & page = <% = I %> '<% if
(I = showPage) {%> selected <% }%>>< % = I %> </option> <% }%> </select> Page
</A> </td>
</Tr>
</Tbody>
</Form>
</Table> </td>
</Tr>
</Table> </td>
</Tr>
</Table> </td>
</Tr>
</Table> </td>
<%
RsArticle. close ();
}
Rs6.close ();
}
Stmt1.close ();
%>