一个非常简单的分页技术MYSQL+JSP 利用了mysql的LIMIT参数
<%
intcateID=0;
if(request.getParameter("cateID")==null)

...{cateID=0;}

else...{
cateID=Integer.parseInt(request.getParameter("cateID"));
}
intnext_page=cateID+1;
intper_page=5;
intpagenum=(cateID*per_page)+1;

if(cateID==0)...{
sql="select*fromBLOG_CONTENTwherelog_IsTop=0orderbylog_IDdescLIMIT0,"+per_page+"";

}else...{
sql="select*fromBLOG_CONTENTwherelog_IsTop=0orderbylog_IDdescLIMIT"+pagenum+","+per_page+"";
}
rst=stmt.executeQuery(sql);

while(rst.next())...{%>
<divclass="content_head"><imgsrc="images/weather/0.gif"alt=""align="absmiddle">
<%=rst.getString("log_Title")%>[
<%=rst.getString("log_PostTime")%>|
<br>
<%=rst.getString("log_Content")%><br>
<br>

<%}%>
<divclass="content_head"align="right"><ahref="default.jsp">回首页</a><ahref="default.jsp?cateID=<%=next_page%>">下一页</a></div>
<spanclass="smalltxt"></span></td>
</tr></table>
</td>
</tr>
</table>
优点:1自己想出来的 2利用了MYSQL 数据库的本身 LIMIT
缺点:现在仅仅实现了 下一个页面功能
<%
intcateID=0;
if(request.getParameter("cateID")==null)
...{cateID=0;}
else...{
cateID=Integer.parseInt(request.getParameter("cateID"));
}
intnext_page=cateID+1;
intper_page=5;
intpagenum=(cateID*per_page)+1;
if(cateID==0)...{
sql="select*fromBLOG_CONTENTwherelog_IsTop=0orderbylog_IDdescLIMIT0,"+per_page+"";
}else...{
sql="select*fromBLOG_CONTENTwherelog_IsTop=0orderbylog_IDdescLIMIT"+pagenum+","+per_page+"";
}
rst=stmt.executeQuery(sql);
while(rst.next())...{%>
<divclass="content_head"><imgsrc="images/weather/0.gif"alt=""align="absmiddle">
<%=rst.getString("log_Title")%>[
<%=rst.getString("log_PostTime")%>|
<br>
<%=rst.getString("log_Content")%><br>
<br>
<%}%>
<divclass="content_head"align="right"><ahref="default.jsp">回首页</a><ahref="default.jsp?cateID=<%=next_page%>">下一页</a></div>
<spanclass="smalltxt"></span></td>
</tr></table>
</td>
</tr>
</table>
本文介绍了一种利用MYSQL数据库LIMIT参数实现的简单分页技术,通过JSP页面展示博客内容,并实现了翻页功能。该技术适用于基本的网站应用。
110

被折叠的 条评论
为什么被折叠?



