📄 list.jsp
字号:
<%@ include file="conn.jsp"%>
<%String classid=request.getParameter("classid");
String sql1="select parentid,layer from scott.class where classid='"+classid+"'";
ResultSet rs=stmt1.executeQuery(sql1);
int tclassid;
if(rs.next()){
tclassid=Integer.parseInt(classid);
if(rs.getInt("parentid")>1){
tclassid=rs.getInt("parentid");
}%>
<html>
<head>
<title>新闻网</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK href="images/css.css" rel=stylesheet type=text/css>
<style type="text/css">
<!--
body {
background-image: url(images/pagebg1.gif);
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
</head>
<body>
<table width="780" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#CACACA">
<tr>
<td bgcolor="#FFFFFF"><%@ include file="top.inc"%>
<table width="780" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="171" valign="top" bgcolor="F7EEE4"><%@ include file="left.inc"%></td>
<td width="609" valign="top"><table width="580" border="0" align="center" cellpadding="5" cellspacing="5">
<tr>
<td width="590" colspan="2"><img src="images/deng<%=tclassid%>.gif" width="580" height="60"></td>
</tr>
</table>
<%String sqlname;
int intPageSize;
int intRowCount;//记录总数
int intPageCount;//总页数
int intPage;//页面参数
String strPage;//定义变量用来传递page
int i,j;
intPageSize=20;//定义每页显示20条记录
strPage=request.getParameter("page");//取得当前的页码
if(strPage==null){//判断初始页面,如果没有显示记录,就置为第一页
intPage=1;
}else{
intPage=Integer.parseInt(strPage);//将strPage转化为整数
if(intPage<1) intPage=1;
}
sqlname="select count(articleid) from scott.article where classid='"+classid+"' order by addtime desc";
rst=stmt.executeQuery(sqlname);
rst.next();
intRowCount=rst.getInt(1);//取得整数保存与intRowCount变量中
intPageCount=(intRowCount+intPageSize-1)/intPageSize;//计算出总页数(记录总数+每页显示的记录-1)/每页显示的记录)
if(intPage>intPageCount)
intPage=intPageCount;
sqlname="select articleid,title,addtime from scott.article where classid='"+classid+"' order by addtime desc";
rst=stmt.executeQuery(sqlname);//执行sql,按照时间先后排序显示
i=(intPage-1)*intPageSize;
for(j=0;j<i;j++)
rst.next();
%>
<%-- 设置intPage参数 --%>
<%if(intRowCount==0){%>
对不起,还没有数据!
<%}else{%>
<%-- 显示每页的数据 (根据i的值判断每页的5条记录) --%>
<table width="560" border="0" align="center" cellpadding="3" cellspacing="3" class="txt1">
<%
i=0;
while(i<intPageSize && rst.next()){
%><tr><td width="4%">
<img src="images/iocn1.gif" width="8" height="7"></td>
<td width="77%" class="txt1"><a href="show.jsp?id=<%=rst.getString("articleid")%>" target="_blank" class="list3"><%=rst.getString("title")%></a> </td>
<td width="19%" class="txt3">[<%=rst.getDate("addtime")%>]</td>
</tr>
<% i++;//通过I循环设置每页的页数
}
}
rst.close();
%><tr><td> </td>
<td align="center"></td> <div align="center">
<p align='center' vAlign='bottom' >
第<%=intPage%>页 共<%=intPageCount%>页
<%if(intPage<intPageCount){%>
<a href="list.jsp?classid=<%=classid%>&page=<%=intPage+1%>" class="list3">下一页</a>
<%}%>
<%if(intPage>1){%>
<a href="list.jsp?classid=<%=classid%>&page=<%=intPage-1%>" class="list3">上一页</a>
<%}%>
</div> <td class="txt3"> </td> </tr>
</table>
</td>
</tr>
</table>
<%@ include file="end.inc"%></td>
</tr>
</table>
</body>
</html>
<% }%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -