<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@page import="bean.ArticleBean"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</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">
</head>
<jsp:useBean id="artBean" class="bean.ArticleBean" scope="page"/>
<jsp:useBean id="artDao" class="dao.ArticleDao" scope="page"/>
<!-- 定义变量赋值 -->
<%!
int currPage=1;//当前页
int rowPage=5;//每页行数
int totalPage;//总页数
int totalRow;//总记录数
int indexBegin;//开始下标
int indexEnd;//结束下标
Vector vData;
%>
<!-- 得到分页数据,并存入session内 -->
<%
Object obj=session.getAttribute("page");
if(obj==null)
{
vData=artDao.list();
session.setAttribute("page",vData);
}else
{
vData=(Vector)obj;
}
%>
<!-- 给变量赋值 -->
<%
String number=request.getParameter("pageNum");
currPage=1;
if(number!=null)
{
currPage=Integer.parseInt(number);
}
totalRow=vData.size();
totalPage=totalRow/rowPage;
if(totalRow%rowPage!=0)
{
totalPage++;
}
indexBegin=(currPage-1)*rowPage;
indexEnd=currPage*rowPage-1;
if(currPage==totalPage)
{
indexEnd=totalRow-1;
}
%>
<body>
<table border=1>
<%
for(int i=indexBegin;i<=indexEnd;i++)
{
artBean=(ArticleBean)vData.get(i);
%>
<tr>
<td><%=artBean.getCaption() %></td>
<td><%=artBean.getContent() %></td>
<td><%=artBean.getUserName() %></td>
</tr>
<%
}
%>
</table>
当前页:<%=currPage %> 总页数:<%=totalPage %>
<%
if(currPage==1)
{
%>
<a style="border-bottom:1px solid #999">首页</a>
<a style="border-bottom:1px solid #999">上一页</a>
<%
}
else
{
%>
<a href="index.jsp?pageNum=1">首页</a>
<a href="index.jsp?pageNum=<%=currPage-1 %>">上一页</a>
<%
}
%>
<%
if(currPage==totalPage)
{
%>
<a style="border-bottom:1px solid #999">下一页</a>
<a style="border-bottom:1px solid #999">尾页</a>
<%
}
else
{
%>
<a href="index.jsp?pageNum=<%=currPage+1 %>">下一页</a>
<a href="index.jsp?pageNum=<%=totalPage %>">尾页</a>
<%
}
%>
</body>
</html>