<ul class="classlist">
<%
//接收新闻主题
String id = request.getParameter("tid");
String countSql = "select count(*) from news";
String pageSql = "select * from (select a.*,rownum mid from news a)b where mid>=? and mid<=?";
int tid = 1;
if(id!=null){//要执行 根据主题查询 的 分页
tid = Integer.valueOf(id);
countSql = "select count(*) from news where tid="+tid;
pageSql = "select * from (select a.*,rownum mid from news a where tid="+tid+")b where mid>=? and mid<=?";
}
//查询新闻总条数
ps = con.prepareStatement(countSql);
rs = ps.executeQuery();
int count = 0;
if(rs.next()){
count = rs.getInt(1);
}
//获取页面
String index = request.getParameter("pageIndex");
int pageIndex = 1;
if(index!=null){
pageIndex = Integer.valueOf(index);
}
//查询新闻
int pageSize = 5;
//求出最大页码
int maxPage = count/pageSize;
if(count%pageSize != 0){
maxPage++;
}
int start = (pageIndex-1)*pageSize+1;
int end = pageIndex*pageSize;
ps = con.prepareStatement(pageSql);
ps.setInt(1, start);
ps.setInt(2, end);
rs = ps.executeQuery();
while(rs.next()){
%>
<li>
<a href='newspages/news_add.html'><%=rs.getString("ntitle") %> </a>
<span> <%=rs.getDate("ndate") %> </span>
</li>
<li class='space'></li>
<%} %>
<p align="right">
<a href="index.jsp<%
if(id!=null){
out.print("?tid="+tid);
}
%>">首页</a>
<a href="index.jsp?pageIndex=<%=pageIndex>1?pageIndex-1:1%><%
if(id!=null){
out.print("&tid="+tid);
}
%>">上一页</a>
当前页数:[<%=pageIndex %>/<%=maxPage %>]
<a href="index.jsp?pageIndex=<%=pageIndex<maxPage?pageIndex+1:maxPage%><%
if(id!=null){
out.print("&tid="+tid);
}
%>">下一页</a>
<a href="index.jsp?pageIndex=<%=maxPage%><%
if(id!=null){
out.print("&tid="+tid);
}
%>">末页</a>
</p>
</ul>
04-02
539
10-06
365