首页 > 编程 > JSP > 正文

高效简单的_jsp分页代码

2019-11-02 14:51:38
字体:
来源:转载
供稿:网友
<%@ page import="java.sql.*,java.i
探索宇宙[www.9-39.com/html/explore/]
o.*,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>&nbsp;</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>点击</b></td>
<td><b>加入时间</b></td>
</tr>
<%
int i;
int ipage=5; //分页单位
int allpage; //总页数
int pages; //接受的页码变数
int cpage=1; //当前页
int spage; //开始页
int allCol=0;
Vector v=null;//资料库连接声明
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";//取总文章数
statement = conn.createStatement();
pagers = statement.executeQuery(pagesql);
 while(pagers.next())
  {
  allCol = pagers.getInt(1);
  System.out.println(allCol);  }
 
//获得总页面数
allpage = (int)Math.ceil((allCol + ipage-1) / ipage);
//判断参数pages是否空
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;
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表