新闻分页显示!
shownews.jsp

<%@page contentType="text/html;charset=GB2312"%>
<%@include file=
"inc.jsp"%>
<Script language=
"JavaScript">
//打开新窗口函数NewsWindow
function NewsWindow(id)
{
window.open('newswind.jsp?id='+id,'infoWin', 'height=400,width=600,scrollbars=yes,resizable=yes');
}
</Script>
<%@include file=
"head.htm"%>
<body bgcolor=
"#999999">
<%! int pageSize=10;
//每页显示的记录数。
int pageCount=0;
//分页后的总页数。
%>
<%-- 客户通过表单提交欲要显示的页码数--%>
<FORM action=
"" method=get >
输入页码数<Input Type=text name=showPage size=4 >
<Input Type=submit name=g value=提交>
</FORM>
<%
sql=
"select * from new_sz order by id desc ";
rs = apple.select(sql);
rs.last();
//获取最后一行的行号:
int lastRow=rs.getRow();
//计算分页后的总页数:
pageCount=(lastRow%pageSize==0)?(lastRow/pageSize):(lastRow/pageSize+1);
//当前显示的初始页数:
int showPage=1;

//告知客户总页数:
%>
<% for(i=1;i<=pageCount;i++);
{out.println(
"<A HREF=show1.jsp>");
out.println(i);
out.println(
"</A>");
}
%>
<P> 共有<%=lastRow%> 条记录
<P> 共有<%=pageCount%>页
<BR>每页显示<%=pageSize%>条记录.
<%
//获取客户想要显示的页数:
String integer=request.getParameter(
"showPage");
if(integer==null)
{ integer=
"1";
}
try {showPage=Integer.parseInt(integer);
}
catch(NumberFormatException e)
{showPage=1;
}
if(showPage<=1)
{showPage=1;
}
if(showPage>=pageCount)
{showPage=pageCount;
}
%>
<BR>目前显示第<%=showPage%>页

<%
//如果要显示第showPage页,那么游标应移到posion的值是:
int posion=(showPage-1)*pageSize+1;
rs.absolute(posion);
// 设置游标的位置;
<tr>
<td width=
"47%">
<div align=
"center">主题</div>
</td>
<td width=
"21%">
<div align=
"center">作者</div>
</td>
<td width=
"32%">
<div align=
"center">时间</div>
</td>
</tr>
<%
for (int i=1;i<=pageSize;i++)
{
%>
<td width=
"47%"><a href="javascript:NewsWindow(<%=rs.getInt("ID")%>)"><u>
<%String title=rs.getString(
"title");
title=new String(title.getBytes(
"ISO-8859-1"),"GB2312" );
%>
<%=title%></u></a></td>
<td width=
"21%" align="center">
<%String author=rs.getString(
"author");
author=new String(author.getBytes(
"ISO-8859-1"),"GB2312" );
%>
<%=author%>
<div align=
"center"></div>
</td>
<td width=
"32%" align="center"><%=rs.getString("Date")%>
<%
out.println(
"</td></tr>");
rs.next();
}

apple.closeConn();

%>
lunzi   2004-11-09 20:45:06 评论:0   阅读:2516   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog