解决方案 »
- 请问如何实现记录会员在我的网站上停留的时间呢
- SSH getHibernateTemplate()的按照条件查询怎么写???
- hibernate的异常,求解,
- java在Linux/Unix中保存文件和建立目录的问题(急-----在上线等!)
- tomcat+mysql问题,找不到jdbc驱动??
- 一个相对路径的问题?
- 求助:java.io.NotSerializableException
- 再次求援!!!!
- catch(Exception e){e.printStackTrace();}是什么意思呀?
- 应该有高手用过 ImageJ吧!!!!!!!(UP有分喽!)
- 网站发帖子的控件,哪有(有图)
- Web页面不能显示数据库数据!求救!
我现在写分页都是以前写好的打成jar包
稍微改下代码就可以实现了没有现成的
给你个资料参考下
http://www.family168.com/tutorial/jsp/html/jsp-ch-15.html
<%@ page import="com.szscz.dao.NewsDAO"%>
<%@ page import="com.szscz.actionForm.NewsForm"%>
<%@ page import="java.sql.*, java.util.Date"%>
<%@ page import="java.text.*"%>
<%! String id,time,title;%>
<script language="javascript" type="text/javascript">
<!--
// 说明:用 JavaScript 实现网页图片等比例缩放 function DrawImage(ImgD,FitWidth,FitHeight)
{
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0)
{ {
if(image.width>FitWidth)
{
ImgD.width=FitWidth;
ImgD.height=(image.height*FitWidth)/image.width;
}
else
{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else
{
if(image.height>FitHeight)
{
ImgD.height=FitHeight;
ImgD.width=(image.width*FitHeight)/image.height;
}
else
{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
}
//-->
</script>
<title>-政策法规</title>
<link href="css/css.css" rel="stylesheet" type="text/css">
<link href="css/mainframe.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
@import url("css/style.css");
-->
</style>
<link href="css/style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
body {
background-image: url(images/bg-0161.gif);
}
-->
</style>
</head>
<%--整个容器开始--%>
<div id="container" class="clearfix">
<%--头部开始--%>
<div id="head">
<jsp:include page="top.jsp" flush="true" />
</div>
<%--头部结束--%>
<div id="daohang">
当前位置:<a href="index.jsp" class="middle">首页</a>>><a href="zhengcefagui.jsp" class="middle">政策法规</a>
</div>
<%--主页面开始--%>
<div id="page" >
<div id="slider" >
<jsp:include page="slider.jsp" flush="true"/>
</div>
<div id="picnew2" class="tableBorder">
<div id="picnew2con" >
<%
int i;
int ipage=18; //分頁單位
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://localhost:1433;DatabaseName=db_szscz";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn = DriverManager.getConnection(kmsdb, "sa", "");
pagesql = "SELECT count(*) FROM tb_news where news_classid='4'";
//取總文章數
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;
}
//判斷起始頁
sql = "select Top "+ipage+" news_id,news_title,news_time from tb_news where news_classid='4' and news_id not in (select top "+(cpage-1)*ipage+" news_id from tb_news order by news_time desc)order by news_time desc";
rs = statement.executeQuery(sql);
while (rs.next())
{
id=rs.getString("news_id");
title=rs.getString("news_title");
time=rs.getString("news_time");
Date s1=java.sql.Date.valueOf(time);
SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd" );
Date date=new Date();//HH:mm:ss
Date s2 = java.sql.Date.valueOf(formatter.format(date));
long a=(s2.getTime()-s1.getTime())/ 1000 / 60 / 60 / 24;
String temppic="";
if(a<20)
temppic="<img src='images/new.gif'/>";
%>
<ul class="nav" >
<li><span><%=temppic%><%=time%></span><a href="news.do?action=newsDetail&news_id=<%=id%>"><%=title%></a></li>
</ul>
<%
}
%>
</div>
<div id="pagelog">
共<%= allCol %>条记录 共<%= allpage %>页 <% if (cpage>1) { %><a href="zhengcefagui.jsp?pages=<%= cpage-1 %>">上一页</a><% } if (cpage<allpage) { %><a href="zhengcefagui.jsp?pages=<%= cpage+1 %>">下一页</a><% } %> / <% for (i=1;i<=allpage;i++) { if (i != pages) {%><a href="zhengcefagui.jsp?pages=<%= i %>"><%= i %></a> <% }} %>
</div>
</div>
</div>
<%--主体页面结束--%>
</div>
<%--脚文件开始--%>
<div id="foot" >
<jsp:include page="bottom.jsp" flush="true" />
</div>
<%--脚文件结束--%>
</div >
<%--整个容器--%>
.这些都可以在Java里计算出来的啊.然后页码就可以循环输出了.
如果有搜索条件,还是做成Form提交的.然后把当前的请求页码发送过去.
这个网站中的代码不错了
2楼的代码也不错。。