下面是我做的分页代码,,运行除了问题,,当我点击不同主题时,,下面分页显示的新闻却是第一个标题下面的新闻

t8759695 2017-10-19 11:24:12
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="cn.jbit.Dao.TopicDao"%>
<%@page import="cn.jbit.DaoImpl.TopicDaoImpl"%>
<%@page import="java.sql.Connection"%>
<%@page import="cn.jbit.util.DatabaseUtil"%>
<%@page import="cn.jbit.Dao.newsDao"%>
<%@page import="cn.jbit.DaoImpl.NewsDaoImpl"%>
<%@page import="cn.jbit.enpity.Topic"%>
<%@page import="cn.jbit.enpity.News"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>管理员页面</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
body{
padding-top: 30px;
padding-left: 30px;
}
#left{
border: 1px solid red;
height: 200px;
width: 200px;
float: left;
}
#left li{
list-style: none;
}
#right{
margin-left:15px;
float: left;
border: 1px solid blue;
width: 700px;
height: 900px;
color: black;

}

#right a{
text-decoration: none;
}


#topic li{
list-style: none;
height:30px;
line-height:30px;
float: left;
margin-right:8px;
font-weight: bolder;

}

#news li{
list-style: none;
height:30px;

line-height:30px;
margin-right:8px;
clear: left;

}
#news span{
float: right;
margin-right: 20px;
}

li a{
color: black;
}
</style>
</head>
<body>
<%
Connection conn = DatabaseUtil.getConnection();
TopicDao topicDao = new TopicDaoImpl(conn);
List<Topic> list1=topicDao.getAllTopics();
request.setAttribute("topics",list1);

newsDao news = new NewsDaoImpl(conn);
String tid = request.getParameter("tid");
List<News> list2 = news.findNews(1);
request.setAttribute("news",list2);
if(tid!=null){
int tid2 = Integer.parseInt(tid);
list2 = news.findNews(tid2);
request.setAttribute("news",list2);
for(int i=0;i<list2.size();i++){
%>
<%=list2.get(i).getNtitle() %><br>

<%
}
}
int count=0; //总行数
int page_count=0; //开始条数
int page_total = (list2.size()%3==0)?(list2.size()/3):(list2.size()/3+1); //总页码
int currPage= 1; //首页
int page_size=3;//一页的行数
String page_cu = request.getParameter("page");
if(page_cu!=null)
currPage = Integer.parseInt(page_cu);
if(currPage<1){
currPage =1;
}
if(currPage>page_total){
currPage = page_total;
}
int Startindex = (currPage-1)*page_size; //开始位置
int endindex = currPage*page_size-1; //结束位置
if(endindex>=list2.size()){
endindex = list2.size()-1;

}
%>
<form action="TopicServlet" method="post">
<div id="left">
<ul>
<li><a href = "newsadd.jsp">添加新闻</a></li>
<li><a href = "">编辑新闻</a></li>
<li><a href = "topicadd.jsp?opr=addtopic">添加主题</a></li>
<li><a href = "topiclist.jsp?opr=update">编辑主题</a></li>
</ul>
</div>
<div id = "right">

<ul id = "topic">
<c:forEach var="topic" items="${topics}">
<li><a href = "guliyuan2.jsp?tid=${topic.tid}">${topic.tname}</a></li>
</c:forEach>

</ul>
<ul id ="news">
<c:forEach var="newsss" items="${news}" step="1" varStatus="i" begin="<%=Startindex %>" end="<%=endindex%>">
<li><a href = "#">${newsss.ntitle}</a><span>${newsss.ncreateDate }</span> </li>
</c:forEach>
<li>
<a href="guliyuan2.jsp?">首页</a>
<a href="guliyuan2.jsp?page=<%= currPage-1 %>">上一页</a>
<a href="guliyuan2.jsp?page=<%= currPage+1 %>">下一页</a>
<a href="guliyuan2.jsp?page=<%=page_total %>">尾页</a>
当前第<%=currPage %>页/共<%=page_total %>页
</li>
</ul>

</div>
</form>
</body>
</html>
...全文
337 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
t8759695 2017-10-21
  • 打赏
  • 举报
回复
就是下面分页时没传参数,,改成这样就行了 <% request.setAttribute("tid",tid); %> <a href="guliyuan2.jsp?">首页</a> <a href="guliyuan2.jsp?page=<%= currPage-1 %>&tid=<%=tid">上一页</a> <a href="guliyuan2.jsp?page=<%= currPage+1 %>&tid=<%=tid">下一页</a> <a href="guliyuan2.jsp?page=<%=page_total %>&tid=<%=tid">尾页</a>
街头小贩 2017-10-19
  • 打赏
  • 举报
回复
切换主题时,分页参数是否传递了

10,607

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧