日期:2014-05-16  浏览次数:20343 次

JSP仿百度分页,谷歌分页页码处理
本文出处: http://blog.csdn.net/tolys/archive/2007/10/06/1813197.aspx
像百度一样的jsp分页效果,像goolge一样的分页效果!
根据设定参数一次取一页记录内容显示
代码如下:
<%@ page language="java" pageEncoding="GB2312"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <base href="<%=basePath%>">

        <title>仿BAIDU & GOOGLE 分页页码显示格式</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <style>
        <!--
            body{
                .p{
                    PADDING-LEFT: 18px; FONT-SIZE: 14px; WORD-SPACING: 4px
                }
            }
        -->
        </style>
    </head>

    <body>
        <div class="p">
            <%
                int pagesize = 10;//每页显示记录数
                int liststep = 20;//最多显示分页页数
                int pages = 1;//默认显示第一页
                if (request.getParameter("pages") != null) {
                    pages = Integer.parseInt(request.getParameter("pages"));//分页页码变量
                }
                //sql="select count(*) from table";//取出记录总数,把*换成记录名性能更加
                int count = 305;//假设取出记录总数
                int pagescount = (int) Math.ceil((double) count / pagesize);//求总页数,ceil(num)取整不小于num
                if (pagescount < pages) {
                    pages = pagescount;//如果分页变量大总页数,则将分页变量设计为总页数
&nbs