2 wangziying1008 wangziying1008 于 2014.01.03 20:58 提问

急!关于mysql+jsp分页显示的问题,请哪位好心的大神帮忙看一下,很急!!谢谢!!

浏览器显示时总是重复出现当前页最后一条信息,是怎么回事啊?
这是jsp代码:
<%
int pageNum = 1;
int pageSize=LunwenDao.PAGE_NUM;
String paramPage = request.getParameter("page");
if (paramPage != null) {
pageNum = Integer.parseInt(paramPage);
}

LunwenDao l = new LunwenDao();

List newsList = l.showLunwenForPage(pageNum);

int prePageNum = pageNum;
int nextPageNum = pageNum;
if (newsList.size() == pageSize)
    nextPageNum = pageNum + 1;
if (pageNum > 1)
    prePageNum = pageNum - 1;
for (int i = 0; i < newsList.size(); i++) {
lunwenxinxibiao ct = (lunwenxinxibiao) newsList.get(i);
%>
<tr valign="top" align="left" bgcolor="#ffffff">
    <td height="30" width="5%">&nbsp;</td>
<td height="30" width="10%"><%=pageSize * (pageNum - 1) + (i + 1)%></td>
<td width="85%"><a href="detaillunwen.jsp?lunwenID=<%=ct.getLunwenID() %>"><%=ct.getLunwen()%>

      [<%=ct.getFabiaoshijian()%>]
<%
}
%>
这是LunwenDao方法:
public List showLunwenForPage(int page ) {
List list = new ArrayList();

int number = 0;
if (page > 1) {
    number = PAGE_NUM * (page - 1);
}
String sql = "select * from lunwenxinxibiao LIMIT "+number+","+PAGE_NUM;
try {
    conn = this.getConn();
    pstmt = conn.prepareStatement(sql);

    rs = pstmt.executeQuery();
    while (rs.next()) {
        lunwenxinxibiao  c = new lunwenxinxibiao();
        c.setLunwenID(rs.getInt("lunwenID"));
        c.setLunwen(rs.getString("lunwen"));
        c.setFabiaoshijian(rs.getString("fabiaoshijian"));
        list.add(c);
    }
} catch (Exception e) {
    e.printStackTrace();
} finally {
    this.closeAll(conn, pstmt, rs);
}

return list;

}
CSDN移动问答这是浏览器里的效果:

Csdn user default icon
上传中...
上传图片
插入图片