Complete instances are displayed on jsp pages, while jsp pages are displayed on jsp pages.
This article describes the implementation of jsp paging display. Share it with you for your reference.
The specific implementation method is as follows:
Copy codeThe Code is as follows: <% @ page contentType = "text/html; charset = gb2312" language = "java" import = "java. SQL. *" errorPage = "" %>
<% @ Include file = "../inc/ChkPwd. jsp" %>
<% @ Include file = "../DB. jsp" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta name = "robots" content = "noindex, nofollow"/>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> Article management </title>
<Link href = "Style.css" rel = "stylesheet" type = "text/css"/>
</Head>
<Body>
<Table width = "98%" height = "77%" border = "0" cellpadding = "0" cellspacing = "0">
<Tr class = "STYLE1">
<Td width = "100%" height = "26" background = "images/admin_bg_1.gif"> <strong> <font color = "# FFFFFF"> -- <span class = "STYLE1"> content management </span> </font> </strong> </td>
</Tr>
<Tr>
<Td colspan = "10">
</Td>
</Tr>
<Tr class = "title">
<Td height = "25" background = "images/admin_bg_1.gif" class = "t2"> |
<%
String op;
String ID = request. getParameter ("id ");
Op = request. getParameter ("op ");
If (op = null ){
Op = "my ";
}
If (op. equals ("del") & ID! = Null ){
String bbb = new String (request. getParameter ("BigClassName"). getBytes ("iso8859_1 "));
Statement stmt_ChannelDEL = conn. createStatement ();
String Sqldel = "delete from hl_news where id =" + ID;
Int shanw.stmt_channeldel.exe cuteUpdate (Sqldel );
If (shan> 0)
{
Out. print ("<script type =" text/javascript "> alert (" deleted successfully! "); Window. location. href = 'hanye _ Manages. jsp? BigClassName = "+ bbb +" '; </script> ");
}
Stmt_ChannelDEL.close ();
Return;
}
Statement TA = conn. createStatement (ResultSet. TYPE_SCROLL_SENSITIVE, ResultSet. CONCUR_READ_ONLY );
String SqlA = "Select * from hl_smallclass WHERE bigname = 'industry news 'order by id asc ";
ResultSet rsa1_ta.exe cuteQuery (SqlA );
While (RsA. next ()){
%>
<A class = 't2 'href = 'hanye _ Manages. jsp? Modi = News & BigClassName = <% = RsA. getString ("smallname") %> '> <% = RsA. getString ("smallname") %> </a> |
<%
}
RsA. close (); // close the record set object
StmtA. close (); // close the statement object
%>
</Td>
</Tr>
<Tr>
<Td height = "20"> </td>
</Tr>
<Tr>
<Td align = "center" valign = "top" bgcolor = "# ECF5FF">
<Form name = "form2" action = "list. asp? Action = delall & modi = News "method =" post ">
<Table width = "100%" cellpadding = "3" cellspacing = "2" bgcolor = "# FFFFFF" style = "word-break: break-all">
<Tr class = "t2">
<Td width = "32" height = "28" align = "center" background = "images/admin_bg_1.gif" bgcolor = "# BBDAFF" class = "STYLE1"> ID </td>
<Td width = "80" align = "center" background = "images/admin_bg_1.gif" bgcolor = "# BBDAFF" class = "STYLE1"> News Category </td>
<Td width = "88" align = "center" background = "images/admin_bg_1.gif" bgcolor = "# BBDAFF" class = "STYLE1"> News class </td>
<Td width = "291" align = "center" background = "images/admin_bg_1.gif" bgcolor = "# BBDAFF" class = "STYLE1" style = "word-break: break-all "> News Title </td>
<Td width = "179" align = "center" background = "images/admin_bg_1.gif" bgcolor = "# BBDAFF" class = "STYLE1"> news images </td>
<Td width = "76" align = "center" background = "images/admin_bg_1.gif" bgcolor = "# BBDAFF" class = "STYLE1"> release date </td>
<Td width = "64" align = "center" background = "images/admin_bg_1.gif" bgcolor = "# BBDAFF" class = "STYLE1"> operation </td>
</Tr>
<%
Int pageSize = 10; // number of articles displayed on each page
Int showPage = 1; // the page number displayed on the current page
Int recCount = 0; // total number of articles in ResultSet
Int pageCount = 0; // the total number of pages after pagination
String SqlArticle;
String toPage = request. getParameter ("page ");
String bgname = new String (request. getParameter ("BigClassName"). getBytes ("iso8859_1 "));
Statement stmt_Article = conn. createStatement (ResultSet. TYPE_SCROLL_SENSITIVE, ResultSet. CONCUR_READ_ONLY );
SqlArticle = "Select * from hl_news where smallname = '" + bgname + "'order by id desc ";
ResultSet rsarticle1_stmt_article.exe cuteQuery (SqlArticle );
If (RsArticle. next ()){
RsArticle. last (); // pointer fly to the end
RecCount = RsArticle. getRow (); // remove the row number of the last row
PageCount = (recCount % pageSize) = 0? (RecCount/pageSize) :( recCount/pageSize) + 1); // returns the total number of pages that can be divided.
If (toPage! = Null)
ShowPage = Integer. parseInt (toPage );
RsArticle. absolute (showPage-1) * pageSize + 1); // jump to the first on the showpage page
For (int I = 1; I <= pageSize; I ++ ){
Int NID = RsArticle. getInt ("ID ");
String img = RsArticle. getString ("img ");
String ttt = RsArticle. getString ("times ");
// Ttt = ttt. substring (0, 10 );
%>
<Tr class = "STYLE1">
<Td width = "32" height = "22" align = "center" bgcolor = "# BBDAFF"> <% = NID %> </td>
<Td align = "center" bgcolor = "# BBDAFF"> <% = RsArticle. getString ("bigname") %> </td>
<Td align = "center" bgcolor = "# BBDAFF"> <% = RsArticle. getString ("smallname") %> </td>
<Td align = "left" bgcolor = "# BBDAFF"> <% = RsArticle. getString ("Title") %> </td>
<Td align = "center" bgcolor = "# BBDAFF"> <a href = "/<% = img %>" target = "_ blank"> <% = img %> </a> </td>
<Td align = "center" bgcolor = "# BBDAFF"> <% = ttt %> </td>
<Td width = "64" align = "center" bgcolor = "# BBDAFF" class = "STYLE1"> <a href = "Hanye_edit.jsp? Id = <% = NID %> & modi = News "> modify </a> | <a href =" Hanye_Manages.jsp? Id = <% = NID %> & op = del & BigClassName = <% = bgname %> "onclick =" return confirm ('cannot be restored after deletion. Are you sure you want to delete it? ') "> Delete </a> </td>
</Tr>
<%
If (! RsArticle. next ())
Break;
}
}
%>
<Input name = 'allid' type = 'den den 'value =>
</Table>
<Table width = "100%" border = "0" align = "center" cellpadding = "0" cellspacing = "0">
<Tr class = "STYLE1">
<Td width = "50%" align = "left" background = "images/admin_bg_1.gif">
<Span class = "t2"> <strong> </strong>
</Span>
<Label>
</Label>
</Td>
<Td width = "56%" align = "center" background = "images/admin_bg_1.gif">
<Div align = "left" class = "t2">
Total <% = pageCount %> pages <% for (int I = 1; I <= pageCount; I ++) {%> <% if (I = showPage) {%> <B> <% = I %> </B> <%} else {%> [<a href = 'hanye _ Manages. jsp? BigClassName = <% = bgname %> & page = <% = I %> & modi = News'> <% = I %> </a>] <% }%>
</Div> </td>
</Tr>
</Table>
</Form>
<Form name = "form1" method = "post" action = "Hanye_Manage.jsp"> <table width = "51%" border = "0" cellspacing = "0" cellpadding = "0">
<Tr class = "t4">
<Td width = "34%" height = "23"> <span class = "STYLE1"> query: </span>
<Label>
<Select name = "select">
<Option value = "ID"> query by ID </option>
<Option value = "title"> query by title </option>
<Option value = "times"> query by time </option>
</Select>
</Label>
<Label>
<Input type = "text" name = "k">
<Input name = "Submit" type = "submit" class = "t5" value = "Submit">
</Label> </td>
</Tr>
</Table>
</Form>
<Br> </td>
</Tr>
</Table>
<%
RsArticle. close ();
Stmt_Article.close ();
Conn. close ();
%>
</Body>
</Html>
I hope this article will help you with jsp program design.