看看这个吧,注意这里分页的计算方法。database.jsp为数据库连接的文件,这个应该不用我给你了吧
***********************
<%
String key=request.getParameter("key");
if(key==null)
{
key="SYSOP";
}
String temppage=request.getParameter("page");
if(temppage==null)
{
temppage="1";
}
int currpage=Integer.parseInt(temppage);
%><html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Java论坛</title>
</SCRIPT>
</head>
<%@ include file="defaultcss.jsp"%>
<%@ include file="menuaction.jsp"%>
<%@ include file="database.jsp" %><%
java.sql.Statement stmtsearch=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String SQL="SELECT * FROM forumgroup WHERE groupenname='"+key+"'";
//out.println(SQL);
ResultSet rssearch=stmtsearch.executeQuery(SQL);
String groupname="版务区";
String groupenname="sys";
String adminuser="SYSOP";
if(rssearch!=null)
{
rssearch.next();
groupname=rssearch.getString(1);
groupenname=rssearch.getString(2);
adminuser=rssearch.getString(4);
rssearch.close();
}
%><%
SQL="SELECT * FROM data WHERE groupenname='"+groupenname+"'"+" ORDER BY posttime DESC";
//out.println(SQL);
ResultSet rslist=stmtsearch.executeQuery(SQL);
rslist.last();
int count=rslist.getRow();
if(count==-1)
count=0;
//注意这里的计算方法
rslist.first();
int pagenumber=20;
int totalpage=count/pagenumber;
if(count>pagenumber*totalpage)
{
totalpage++;
}
if(currpage>totalpage)
{
currpage=1;
}
if(currpage<=0)
{
currpage=1;
}
int currindex=currpage*pagenumber-20;
//游标走到当前记录
rslist.absolute(currindex);
//out.println(currindex);
if(totalpage==0)
{
currpage=0;
}
%><%
String prevlink="";
String nextlink="";
String firstlink="";
String lastlink="";
String editlink="";
String deletelink="";
String backlink="</a>";//set the firstlink
if(totalpage==0)
{
firstlink="<a href=list.jsp?key="+groupenname+"&page=0>";
}
else
{
firstlink="<a href=list.jsp?key="+groupenname+"&page=1>";
}//set the prevlink
if(currpage-1>=1)
{
prevlink="<a href=list.jsp?key="+groupenname+"&page="+(currpage-1)+">";
}
if(currpage-1<1)
{
prevlink=firstlink;
}//set the nextlink
if(currpage+1<=totalpage)
{
nextlink="<a href=list.jsp?key="+groupenname+"&page="+(currpage+1)+">";
}
if(currpage+1>totalpage)
{
nextlink="<a href=list.jsp?key="+groupenname+"&page="+totalpage+">";
}lastlink="<a href=list.jsp?key="+groupenname+"&page="+totalpage+">";//设定Session,可能用不上,临时的
session.putValue("prevlink",prevlink);
session.putValue("nextlink",nextlink);
session.putValue("firstlink",firstlink);
session.putValue("lastlink",lastlink);
session.putValue("editlink",editlink);
session.putValue("deletelink",deletelink);
session.putValue("backlink",backlink);
%>
<body LANGUAGE=javascript onload="return window_onload()">
<table border="0" width="100%" height="521" cellspacing="0" cellpadding="0">
<%@ include file="toptable.jsp"%>
<tr>
<td width="2%" height="13"></td>
<td width="92%" height="32" colspan="5" rowspan="2">
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="80%" height="26">
<tr bgcolor="#efefef">
<td width="25%" height="24"></td>
<td width="50%" height="24" align="center"><font color="red" size="2">Java技术讨论区(<%=groupname%>信区)</font></td>
<td width="25%" height="24"></td>
</tr>
</table>
</center>
</div>
</td>
</tr>
<tr><td width="2%" height="13"></td></tr>
<tr>
<td width="2%" height="16"></td>
<td width="2%" height="284" rowspan="18" background="img/shu.gif"> </td>
<td width="92%" height="284" colspan="5" rowspan="18">
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="1" width="99%" height="246">
<tr>
<td width="10%" height="29" align="center"><font color="blue" size="2"><%=groupenname%>信区</font></td>
<td width="40%" height="29" align="center"><font color="blue" size="2">文章数:<%=count%></font></td>
<td width="18%" height="29" align="center"><font color="blue" size="2">页数:<%=totalpage%></font></td>
<td width="7%" height="29" align="center"><font color="blue" size="2"></font></td>
<td width="25%" height="29" align="center"><font color="red" size="2">斑竹:<%=adminuser%></font></td>
</tr>
<tr bgcolor='#DCEDED'>
<td width='10%' height='29' align='center'><font color='blue'size='2'>编号</font></td>
<td width='40%' height='29'><font color='blue'size='2'>主题</font></td>
<td width='18%' height='29' align='center'><font color='blue'size='2'>作者</font></td>
<td width='7%' height='29' align='center'><font color='blue'size='2'>回文数</font></td>
<td width='25%' height='29' align='center'><font color='blue'size='2'>发表时间</font></td>
</tr>
<%
int i=0;
while(rslist.next())
{
int id=rslist.getInt(13);
String author=rslist.getString(4);
%>
<tr bgcolor='#efefef'>
<td width='10%' height='29'><font size='2' color='blue'><%=id%></font></td>
<td width='40%' height='29'><font size='2' color='blue'><a href="view.jsp?id=<%=id%>"><%=rslist.getString(1)%></a></font></td>
<td width='18%' height='29'><font size='2' color='blue'><a href="viewuser.jsp?key=<%=author%>"><%=author%></a></font></td>
<td width='7%' height='29'><font size='2' color='blue'><%=rslist.getInt(11)%></font></td>
<td width='25%' height='29'><font size='2' color='blue'><%=rslist.getDate(7)%></font></td>
</tr>
<%
i++;
if(i==pagenumber)
break;
}
rslist.close();
%>
</table>
</center>
</div>
</td>
<td width="2%" height="284" rowspan="18"></td>
<td width="2%" height="284" rowspan="18" background="img/shu.gif"> </td>
</tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="12"></td></tr>
<tr>
<td width="2%" height="41" rowspan="2"></td>
<td width="2%" height="41" background="img/shu.gif" rowspan="2"></td>
<form action="jump.jsp" method="post">
<td width="92%" height="27" colspan="5">
<font color="blue" size="2">当前页:第<%=currpage%>页</font>
<font color="red">==></font>
<font color="blue" size="2">
|
<%=firstlink%>第一页<%=backlink%>
|
<%=prevlink%>上一页<%=backlink%>
|
<%=nextlink%>下一页<%=backlink%>
|
<%=lastlink%>末一页<%=backlink%>
|
</font>
<font color="red">==></font>
<font color="blue" size="2">跳转到:</font>
<select name="page">
<%
for(int j=0;j<totalpage;j++)
{
%>
<option value="<%=j+1%>">第<%=j+1%>页</option>
<%
}
%>
</select>
<input type="hidden" value="<%=groupenname%>" name="key">
<input type="submit" value="马上跳转">
</td>
</form>
<td width="2%" height="41" rowspan="2" background="img/shu.gif"></td>
<td width="2%" height="41" background="img/shu.gif" rowspan="2"></td>
</tr>
<tr>
<td width="92%" height="18" colspan="5" background="img/bottom.gif"> </td>
</tr>
</table>
<%@ include file="menu.jsp"%>
<%
conn.close();
%>
</body>
<html>
***********************
<%
String key=request.getParameter("key");
if(key==null)
{
key="SYSOP";
}
String temppage=request.getParameter("page");
if(temppage==null)
{
temppage="1";
}
int currpage=Integer.parseInt(temppage);
%><html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Java论坛</title>
</SCRIPT>
</head>
<%@ include file="defaultcss.jsp"%>
<%@ include file="menuaction.jsp"%>
<%@ include file="database.jsp" %><%
java.sql.Statement stmtsearch=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String SQL="SELECT * FROM forumgroup WHERE groupenname='"+key+"'";
//out.println(SQL);
ResultSet rssearch=stmtsearch.executeQuery(SQL);
String groupname="版务区";
String groupenname="sys";
String adminuser="SYSOP";
if(rssearch!=null)
{
rssearch.next();
groupname=rssearch.getString(1);
groupenname=rssearch.getString(2);
adminuser=rssearch.getString(4);
rssearch.close();
}
%><%
SQL="SELECT * FROM data WHERE groupenname='"+groupenname+"'"+" ORDER BY posttime DESC";
//out.println(SQL);
ResultSet rslist=stmtsearch.executeQuery(SQL);
rslist.last();
int count=rslist.getRow();
if(count==-1)
count=0;
//注意这里的计算方法
rslist.first();
int pagenumber=20;
int totalpage=count/pagenumber;
if(count>pagenumber*totalpage)
{
totalpage++;
}
if(currpage>totalpage)
{
currpage=1;
}
if(currpage<=0)
{
currpage=1;
}
int currindex=currpage*pagenumber-20;
//游标走到当前记录
rslist.absolute(currindex);
//out.println(currindex);
if(totalpage==0)
{
currpage=0;
}
%><%
String prevlink="";
String nextlink="";
String firstlink="";
String lastlink="";
String editlink="";
String deletelink="";
String backlink="</a>";//set the firstlink
if(totalpage==0)
{
firstlink="<a href=list.jsp?key="+groupenname+"&page=0>";
}
else
{
firstlink="<a href=list.jsp?key="+groupenname+"&page=1>";
}//set the prevlink
if(currpage-1>=1)
{
prevlink="<a href=list.jsp?key="+groupenname+"&page="+(currpage-1)+">";
}
if(currpage-1<1)
{
prevlink=firstlink;
}//set the nextlink
if(currpage+1<=totalpage)
{
nextlink="<a href=list.jsp?key="+groupenname+"&page="+(currpage+1)+">";
}
if(currpage+1>totalpage)
{
nextlink="<a href=list.jsp?key="+groupenname+"&page="+totalpage+">";
}lastlink="<a href=list.jsp?key="+groupenname+"&page="+totalpage+">";//设定Session,可能用不上,临时的
session.putValue("prevlink",prevlink);
session.putValue("nextlink",nextlink);
session.putValue("firstlink",firstlink);
session.putValue("lastlink",lastlink);
session.putValue("editlink",editlink);
session.putValue("deletelink",deletelink);
session.putValue("backlink",backlink);
%>
<body LANGUAGE=javascript onload="return window_onload()">
<table border="0" width="100%" height="521" cellspacing="0" cellpadding="0">
<%@ include file="toptable.jsp"%>
<tr>
<td width="2%" height="13"></td>
<td width="92%" height="32" colspan="5" rowspan="2">
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="80%" height="26">
<tr bgcolor="#efefef">
<td width="25%" height="24"></td>
<td width="50%" height="24" align="center"><font color="red" size="2">Java技术讨论区(<%=groupname%>信区)</font></td>
<td width="25%" height="24"></td>
</tr>
</table>
</center>
</div>
</td>
</tr>
<tr><td width="2%" height="13"></td></tr>
<tr>
<td width="2%" height="16"></td>
<td width="2%" height="284" rowspan="18" background="img/shu.gif"> </td>
<td width="92%" height="284" colspan="5" rowspan="18">
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="1" width="99%" height="246">
<tr>
<td width="10%" height="29" align="center"><font color="blue" size="2"><%=groupenname%>信区</font></td>
<td width="40%" height="29" align="center"><font color="blue" size="2">文章数:<%=count%></font></td>
<td width="18%" height="29" align="center"><font color="blue" size="2">页数:<%=totalpage%></font></td>
<td width="7%" height="29" align="center"><font color="blue" size="2"></font></td>
<td width="25%" height="29" align="center"><font color="red" size="2">斑竹:<%=adminuser%></font></td>
</tr>
<tr bgcolor='#DCEDED'>
<td width='10%' height='29' align='center'><font color='blue'size='2'>编号</font></td>
<td width='40%' height='29'><font color='blue'size='2'>主题</font></td>
<td width='18%' height='29' align='center'><font color='blue'size='2'>作者</font></td>
<td width='7%' height='29' align='center'><font color='blue'size='2'>回文数</font></td>
<td width='25%' height='29' align='center'><font color='blue'size='2'>发表时间</font></td>
</tr>
<%
int i=0;
while(rslist.next())
{
int id=rslist.getInt(13);
String author=rslist.getString(4);
%>
<tr bgcolor='#efefef'>
<td width='10%' height='29'><font size='2' color='blue'><%=id%></font></td>
<td width='40%' height='29'><font size='2' color='blue'><a href="view.jsp?id=<%=id%>"><%=rslist.getString(1)%></a></font></td>
<td width='18%' height='29'><font size='2' color='blue'><a href="viewuser.jsp?key=<%=author%>"><%=author%></a></font></td>
<td width='7%' height='29'><font size='2' color='blue'><%=rslist.getInt(11)%></font></td>
<td width='25%' height='29'><font size='2' color='blue'><%=rslist.getDate(7)%></font></td>
</tr>
<%
i++;
if(i==pagenumber)
break;
}
rslist.close();
%>
</table>
</center>
</div>
</td>
<td width="2%" height="284" rowspan="18"></td>
<td width="2%" height="284" rowspan="18" background="img/shu.gif"> </td>
</tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="16"></td></tr>
<tr><td width="2%" height="12"></td></tr>
<tr>
<td width="2%" height="41" rowspan="2"></td>
<td width="2%" height="41" background="img/shu.gif" rowspan="2"></td>
<form action="jump.jsp" method="post">
<td width="92%" height="27" colspan="5">
<font color="blue" size="2">当前页:第<%=currpage%>页</font>
<font color="red">==></font>
<font color="blue" size="2">
|
<%=firstlink%>第一页<%=backlink%>
|
<%=prevlink%>上一页<%=backlink%>
|
<%=nextlink%>下一页<%=backlink%>
|
<%=lastlink%>末一页<%=backlink%>
|
</font>
<font color="red">==></font>
<font color="blue" size="2">跳转到:</font>
<select name="page">
<%
for(int j=0;j<totalpage;j++)
{
%>
<option value="<%=j+1%>">第<%=j+1%>页</option>
<%
}
%>
</select>
<input type="hidden" value="<%=groupenname%>" name="key">
<input type="submit" value="马上跳转">
</td>
</form>
<td width="2%" height="41" rowspan="2" background="img/shu.gif"></td>
<td width="2%" height="41" background="img/shu.gif" rowspan="2"></td>
</tr>
<tr>
<td width="92%" height="18" colspan="5" background="img/bottom.gif"> </td>
</tr>
</table>
<%@ include file="menu.jsp"%>
<%
conn.close();
%>
</body>
<html>
but:如果时ORACLE数据库,在用createStatement()时带参数,则RS返回的结果有些类型的数据时16进制,如不带参数,RS的指针定位的很多方法不能用如absolute(),只能用Next(),这一点要注意!
下面的描述是否正确:JSP程序由页面部分和bean部分组成,
其中页面部分用HTML语言来编写,bean用java语言编写,在HTML里
调用bean里的接口函数?
整个程序文件都给你了,还不给分!你太过分了!!
俺们那个都是东北人,俺们那个没有这种人!