Java basics-efficient and simple Jsp paging source code

Source: Internet
Author: User
Java basics-efficient and simple Jsp paging source code-general Linux technology-Linux programming and kernel information. The following is a detailed description.
CODE: <% @ page import = "java. SQL. *, java. io. *, java. util. *" %>
<% @ Page language = "java" pageEncoding = "Big5" %>
<%! String au_id, au_lname, au_fname, phone, address, city, state; %>
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<TITLE & gtArticleList </TITLE>
<Link rel = "stylesheet" href = "style.css">
</Head>
<Body bgcolor = "# FFFFFF">

<Table width = "760" border = "0" cellspacing = "0" cellpadding = "0" align = "center">
<Tr>
<Td>
<Table width = "750" border = "0" cellspacing = "2" cellpadding = "2" align = "center">
<Tr align = "center">
<Td> </td>
</Tr>
<Tr>
<Td>
<Table width = "740" border = "0" cellspacing = "1" cellpadding = "1" align = "center">
<Tr align = "center" bgcolor = "# CCCCCC">
<Td> <B>? </B> </td>
<Td> <B & gt author </B> </td>
<Td> <B>? Type </B> </td>
<Td> <B> ??? </B> </td>
<Td> <B & gt join? R? </B> </td>
</Tr>
<%
Int I;
Int ipage = 5; // What is the score ?? Bytes
Int allpage ;//???
Int pages; // accepted ????
Int cpage = 1 ;//? Before?
Int spage ;//? Start?
Int allCol = 0;
Vector v = null;

//? Expected? Connecting B? Ming
Connection conn = null;
Java. lang. String SQL, pagesql;
Java. SQL. ResultSet rs, pagers;
Statement statement = null;
String kmsdb = "jdbc: microsoft: sqlserver: // 127.0.0.1: 1433; DatabaseName = DBName ";
Class. forName ("com. microsoft. jdbc. sqlserver. SQLServerDriver ");
Conn = DriverManager. getConnection (kmsdb, "user", "pwd ");

Pagesql = "select count (*) FROM Authors ";

// Get? Article?
Statement = conn. createStatement ();
Pagers = statement.exe cuteQuery (pagesql );
While (pagers. next ())
{
AllCol = pagers. getInt (1 );
System. out. println (allCol );

}

//? ?? Face?
Allpage = (int) Math. ceil (allCol + ipage-1)/ipage );
// Judge ???? Is ages empty?
If (request. getParameter ("pages") = null ){
Pages = 1;
} Else {
Pages = new Integer (request. getParameter ("pages"). intValue ();
System. out. println (pages );
}
// Judge? Why? Before?
If (pages> allpage | pages = 0)
{Cpage = 1 ;}
Else
{
Cpage = pages;
}
// Judge? Why?
SQL = "select Top" + ipage + "au_id, au_lname, au_fname, address, phone from authors where au_id not in (select top" + (cpage-1) * ipage + "au_id from authors order by au_id desc) order by au_id desc ";
Rs = statement.exe cuteQuery (SQL );
While (rs. next ())
{
Au_id = rs. getString ("au_id ");
Au_lname = rs. getString ("au_lname ");
Au_fname = rs. getString ("au_fname ");
Phone = rs. getString ("phone ");
Address = rs. getString ("address ");

%>
<Td width = "300"> <% = au_id %> </a> </td>
<Td width = "300"> <% = au_lname %> </a> </td>
<Td width = "300"> <% = au_fname %> </a> </td>
<Td width = "300"> <% = phone %> </a> </td>
<Td width = "300"> <% = address %> </a> </td>
</Tr>
<%
} %>
<Tr bgcolor = "# CCCCCC">
<Td colspan = "5" align = "right" valign = "middle" & gt total <% = allCol %>? L ?? Total <% = allpage %>? <% If (cpage & gt1) {%> <a href = "fy. jsp? Pages = <% = cpage-1 %> "> </a> <%} if (cpage <allpage) {%> <a href = "fy. jsp? Pages = <% = cpage + 1%> "> </a> <% }%>/<% (I = 1; I <= allpage; I ++) {if (I! = Pages) {%> <a href = "fy. jsp? Pages = <% = I %> "> <% = I %> </a> <% }%> </td>
</Tr>
</Table>
</Td>
</Tr>
</Table>
</Td>
</Tr>
</Table>
</Body>
</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.