高效简单的JSP分?
类别: JSP教程
<%@ 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">
</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>作者</b></td>
<td><b>??型</b></td>
<td><b>?c?籀lt;/b></td>
<td><b>加入?r殓</b></td>
</tr>
<%
int i;
int ipage=5; //分???挝患br> int allpage; //?????导br> int pages; //接受的??瘁???导br> int cpage=1; //??前??
int spage; //檫始??
int allCol=0;
Vector v=null;
//儋料?爝B接??明
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";
//取??文章?导br> statement = conn.createStatement();
pagers = statement.executeQuery(pagesql);
while(pagers.next())
{
allCol = pagers.getInt(1);
System.out.println(allCol);
}
//?@得????面?导br> allpage = (int)Math.ceil((allCol + ipage-1) / ipage);
//判?????叼ages是否空
if (request.getParameter("pages")==null) {
pages=1;
} else {
pages = new Integer(request.getParameter("pages")).intValue();
System.out.println(pages);
}
//判?喈?前??
if(pages > allpage || pages == 0)
{cpage = 1;}
else
{
cpage = pages;
}
//判?嗥鹗柬?
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");
%>
<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">共 <%= allCol %>?l???? 共 <%= allpage %>?? <% if (cpage>1) { %><a href="fy.jsp?pages=<%= cpage-1 %>"><img src="images/prev.gif" border="0"></a><% } if (cpage<allpage) { %><a href="fy.jsp?pages=<%= cpage+1 %>"><img src="images/next.gif" border="0"></a><% } %> / <% for (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>
<%@ 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">
</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>作者</b></td>
<td><b>??型</b></td>
<td><b>?c?籀lt;/b></td>
<td><b>加入?r殓</b></td>
</tr>
<%
int i;
int ipage=5; //分???挝患br> int allpage; //?????导br> int pages; //接受的??瘁???导br> int cpage=1; //??前??
int spage; //檫始??
int allCol=0;
Vector v=null;
//儋料?爝B接??明
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";
//取??文章?导br> statement = conn.createStatement();
pagers = statement.executeQuery(pagesql);
while(pagers.next())
{
allCol = pagers.getInt(1);
System.out.println(allCol);
}
//?@得????面?导br> allpage = (int)Math.ceil((allCol + ipage-1) / ipage);
//判?????叼ages是否空
if (request.getParameter("pages")==null) {
pages=1;
} else {
pages = new Integer(request.getParameter("pages")).intValue();
System.out.println(pages);
}
//判?喈?前??
if(pages > allpage || pages == 0)
{cpage = 1;}
else
{
cpage = pages;
}
//判?嗥鹗柬?
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");
%>
<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">共 <%= allCol %>?l???? 共 <%= allpage %>?? <% if (cpage>1) { %><a href="fy.jsp?pages=<%= cpage-1 %>"><img src="images/prev.gif" border="0"></a><% } if (cpage<allpage) { %><a href="fy.jsp?pages=<%= cpage+1 %>"><img src="images/next.gif" border="0"></a><% } %> / <% for (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>
- 上一篇: STRUTS下JSP页面传递复选框值技巧
- 下一篇: 会话状态
-= 资 源 教 程 =-
文 章 搜 索