网站的分页显示

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="qrnu.db.ConMysql" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<%     ResultSet rs=new ConMysql().syQuery();
	   int pagesize=10;
	   rs.first();
	   rs.last();
	   int RecordCount=rs.getRow();
	   rs.first();
	   int maxPage=0;
	   maxPage=(RecordCount%pagesize==0)?(RecordCount/pagesize):((RecordCount/pagesize)+1);
%>


</head>

<body>

<%
  String str=(String)request.getParameter("Page");
  
	   if(str==null){
	   		str="0";
			}
		  int Page=Integer.parseInt(str);
		  
	   if(Page<1){
	   		Page=1;
			}else{
			if(Page>maxPage){
				Page=maxPage;
			}
		}
		rs.absolute((Page-1)*pagesize+1);
		
  %>
<table width="286" border="1">
  <tr>
    <td width="86">city_id</td>
    <td width="184">province</td>
  </tr>
  
  <% for(int i=1;i<pagesize&&rs.next();i++){  %>
			<tr>
			<td><% String s=rs.getString(1);out.print(s);%></td>
			<td><% String s2=rs.getString(2);out.print(s2);%></td>
		
		</tr>
		<% }%>
</table>

<table width="287" border="1">
  <tr>
   <%if(Page==4){
   	out.write("cheng");
	}
	%>
  <% if(Page>0&&Page<=maxPage){%>
    <td width="67">
					<a href="pagedisplay.jsp?Page=1">
					第一页</a></td>
    <td width="27">
					<a href="pagedisplay.jsp?Page=<%=maxPage%>">
					末页</a></td>
    <td width="49">
					<a href="pagedisplay.jsp?Page=<%=Page-1%>">
					前一页</a></td>
    <td width="62"><a href="pagedisplay.jsp?Page=<%=Page+1 %>">
					下一页</a></td>
    <td width="48">第几页</td>
	<%}%>
  </tr>
</table>
<p><%out.write(Page);%></p>
</body>
</html>
 

你可能感兴趣的:(html,sql,jsp,XHTML)