Efficient and simple JSP pages

Source: Internet
Author: User
JS <%@ 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>ArticleList</TITLE>
<link rel= "stylesheet" href= "Style.css" >
<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" >
&LT;TR align= "center" >
<td> </td>
</tr>
<tr>
<td>
<table width= "740" border= "0" cellspacing= "1" cellpadding= "1" align= "Center" >
&LT;TR align= "center" bgcolor= "#CCCCCC" >
<td><b> title </b></td>
<td><b> author </b></td>
<td><b> Types </b></td>
<td><b> Click </b></td>
<td><b> Join Time </b></td>
</tr>
<%
int i;
int ipage=5; Pages
int allpage; Page numbers
int pages; The number of pages accepted
int cpage=1; When you are in front of
int spage; Start Page
int allcol=0;
Vector V=null;

Data Library Connection sounds
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";

Take the total number of articles
statement = Conn.createstatement ();
pagers = Statement.executequery (pagesql);
while (Pagers.next ())
{
Allcol = Pagers.getint (1);
System.out.println (Allcol);

}

Get the number of pages
Allpage = (int) Math.ceil (allcol + ipage-1)/ipage);
Whether the number of pages is empty
if (Request.getparameter ("pages") ==null) {
Pages=1;
} else {
pages = new Integer (Request.getparameter ("pages")). Intvalue ();
SYSTEM.OUT.PRINTLN (pages);
}
To judge the front page
if (pages > Allpage | | pages = 0)
{cpage = 1;}
Else
{
cpage = pages;
}
The starting page is judged
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.executequery (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");

%>
&LT;TD width= "><%= au_id%></a></td>"
&LT;TD width= "><%= au_lname%></a></td>"
&LT;TD width= "><%= au_fname%></a></td>"
&LT;TD width= "><%=" Phone%></a></td>
&LT;TD width= "><%=" Address%></a></td>
</tr>
<%
}%>
<tr bgcolor= "#CCCCCC" >
&LT;TD colspan= "5" align= "right" valign= "middle" > A total of <%= allcol%> a total <%= allpage%> page <% if (cpage>1) {%><a href= "fy.jsp?pages=<%= cpage-1%>" ></a><%} if (cpage<allpage) {%><a href= "fy.jsp?pages=<%= cpage+1%>" ></a><%}%>/<% for (i=1;i<= allpage;i++) {if (I!= pages) {%><a href= "fy.jsp?pages=<%= i%>" ><%= i%></a> <%}}%&GT;&L T;/td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>





Related Article

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.