<%@ page contentType="text/html;charset=GBK" language="java" import="java.sql.*,java.util.*" errorPage="" %>
<html>
<%@ include file="top.jsp"%><link href="css.css" rel="stylesheet" type="text/css">
<div align="center">
<center>
<table width="778" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td width="0%" height="25" bgcolor="#DBC2B0" align="center">
<font color="#FFFFFF"><b>新闻热点</b></font></td>
</tr>
<%
String mypage;
int intpage=1;
mypage=request.getParameter("page");
if(mypage=="")
intpage=1;
if(!mdb.IsInt(mypage))
intpage=1;
if(mdb.IsInt(mypage))
intpage=Integer.parseInt(mypage);
if(intpage<1)
intpage=1;
mypage=Integer.toString(intpage);
int curIndex=1;
int PageSize =10; //设置每张网页显示10条记录
int ShowPage = 1; //设置欲显示的页数
int RowCount = 0; //ResultSet的记录数目
int PageCount = 0; //ResultSet分页后的总页数
int duoyu=0;
RowCount=mdb.getCount("Select count(*) as count from news order by news_ID DESC");
System.out.println(RowCount);
duoyu=RowCount % PageSize;
System.out.println(duoyu+"llllllllllllll");
System.out.println(RowCount+"ddddddddd");
System.out.println(PageSize+"eeeeeeeeee");
if(duoyu==0)
{
PageCount=RowCount/PageSize;
}
else{
PageCount=(RowCount-duoyu)/PageSize;
PageCount++;
}
ShowPage=intpage;
if(ShowPage>PageCount)
{
ShowPage=PageCount;
}
else if(ShowPage<=0)
{
ShowPage = 1;
}
curIndex=(ShowPage - 1)*PageSize;
if(curIndex==0){
curIndex=-1;
}
//计算欲显示页的第一笔记录位置
%>
<!----------------------one showing unit------------------------------->
<%
//利用For循环配合PageSize属性输出一页中的记录
int i=1,news_id,linshi=1;
linshi=ShowPage;
String news_title;
Collection coll=mdb.getCollection("Select * from news order by news_ID DESC",new String[]{"news_id","news_title","news_date"},curIndex);
if(coll.size()>0){
for(Iterator it=coll.iterator(); it.hasNext()&&i<=PageSize;){
i++;
UniversalValueObject uvo=(UniversalValueObject)it.next(); news_id=uvo.getInt("news_id");
news_title=uvo.getString("news_title");
if(news_title.length()>20)
{
news_title.substring(0,20);
news_title=news_title+"...";
}
%>
<tr>
<td height="2">
<img src="img/pics/biao.gif" width="15" height="18"> <a href="news.jsp?news_id=<%=news_id%>"><%=news_title%>…… (<%=uvo.getString("news_date")%>)
</td>
</tr>
<%
//下面的if判断语句用于防止输出最后一页记录时,
//将记录指标移至最后一笔记录之后
//跳出for循环
}
%>
<!-----------------------shonwing unit end----------------------------------------------->
<tr>
<td width=478 height="23">
<p align="right">第<%=ShowPage%>页/共<%=PageCount%>页,共<%=RowCount%>条新闻
<%
linshi=ShowPage-1;
if(linshi>0)
{%><a href="allnews.jsp?ToPage=<%=linshi%>">上一页</a>
<%
}else
{%>
上一页
<%} linshi=ShowPage+1;
if(linshi<=PageCount)
{%>
<a href="allnews.jsp?ToPage=<%=linshi%>">下一页</a>
<%
System.out.println(linshi+"sssssssssssss");
System.out.println(PageCount+"PageCount");}else
{%>
下一页
<%}%>
</font></p>
<%
}
else
{//数据库中无新闻
out.print("对不起,没有新闻!");
}%>
</table>
</center>
</div><%@ include file="copy.jsp"%>
</body>
</html>
<html>
<%@ include file="top.jsp"%><link href="css.css" rel="stylesheet" type="text/css">
<div align="center">
<center>
<table width="778" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td width="0%" height="25" bgcolor="#DBC2B0" align="center">
<font color="#FFFFFF"><b>新闻热点</b></font></td>
</tr>
<%
String mypage;
int intpage=1;
mypage=request.getParameter("page");
if(mypage=="")
intpage=1;
if(!mdb.IsInt(mypage))
intpage=1;
if(mdb.IsInt(mypage))
intpage=Integer.parseInt(mypage);
if(intpage<1)
intpage=1;
mypage=Integer.toString(intpage);
int curIndex=1;
int PageSize =10; //设置每张网页显示10条记录
int ShowPage = 1; //设置欲显示的页数
int RowCount = 0; //ResultSet的记录数目
int PageCount = 0; //ResultSet分页后的总页数
int duoyu=0;
RowCount=mdb.getCount("Select count(*) as count from news order by news_ID DESC");
System.out.println(RowCount);
duoyu=RowCount % PageSize;
System.out.println(duoyu+"llllllllllllll");
System.out.println(RowCount+"ddddddddd");
System.out.println(PageSize+"eeeeeeeeee");
if(duoyu==0)
{
PageCount=RowCount/PageSize;
}
else{
PageCount=(RowCount-duoyu)/PageSize;
PageCount++;
}
ShowPage=intpage;
if(ShowPage>PageCount)
{
ShowPage=PageCount;
}
else if(ShowPage<=0)
{
ShowPage = 1;
}
curIndex=(ShowPage - 1)*PageSize;
if(curIndex==0){
curIndex=-1;
}
//计算欲显示页的第一笔记录位置
%>
<!----------------------one showing unit------------------------------->
<%
//利用For循环配合PageSize属性输出一页中的记录
int i=1,news_id,linshi=1;
linshi=ShowPage;
String news_title;
Collection coll=mdb.getCollection("Select * from news order by news_ID DESC",new String[]{"news_id","news_title","news_date"},curIndex);
if(coll.size()>0){
for(Iterator it=coll.iterator(); it.hasNext()&&i<=PageSize;){
i++;
UniversalValueObject uvo=(UniversalValueObject)it.next(); news_id=uvo.getInt("news_id");
news_title=uvo.getString("news_title");
if(news_title.length()>20)
{
news_title.substring(0,20);
news_title=news_title+"...";
}
%>
<tr>
<td height="2">
<img src="img/pics/biao.gif" width="15" height="18"> <a href="news.jsp?news_id=<%=news_id%>"><%=news_title%>…… (<%=uvo.getString("news_date")%>)
</td>
</tr>
<%
//下面的if判断语句用于防止输出最后一页记录时,
//将记录指标移至最后一笔记录之后
//跳出for循环
}
%>
<!-----------------------shonwing unit end----------------------------------------------->
<tr>
<td width=478 height="23">
<p align="right">第<%=ShowPage%>页/共<%=PageCount%>页,共<%=RowCount%>条新闻
<%
linshi=ShowPage-1;
if(linshi>0)
{%><a href="allnews.jsp?ToPage=<%=linshi%>">上一页</a>
<%
}else
{%>
上一页
<%} linshi=ShowPage+1;
if(linshi<=PageCount)
{%>
<a href="allnews.jsp?ToPage=<%=linshi%>">下一页</a>
<%
System.out.println(linshi+"sssssssssssss");
System.out.println(PageCount+"PageCount");}else
{%>
下一页
<%}%>
</font></p>
<%
}
else
{//数据库中无新闻
out.print("对不起,没有新闻!");
}%>
</table>
</center>
</div><%@ include file="copy.jsp"%>
</body>
</html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货