jsp分页操作

<%@ page language="java" import="java.util.*,cn.com.dao.*,cn.com.model.*,cn.com.service.impl.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'ceshi.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">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
<%
	UserServiceImpl usi = new UserServiceImpl();
	User user = null;
	
	int intPageSize;//一页显示的记录数
	int intRowCount;//记录总数
	int intPageCount;//总页数
	int intPage;//待显示的页码
	
	int layer;
	int idlayer;
	idlayer = 1;
	String outtext = "";
	String strPage;
	int j;
	int i;
	//设置一页显示的记录数
	intPageSize = 10;//一页显示10条信息
	//取得待显示的页码
	strPage = request.getParameter("page");
	if(strPage == null){//表明在QueryString中没有page这个参数,此时显示第一页数据
		intPage = 1;
	}else{
		intPage = Integer.parseInt(strPage);
		if(intPage<1)
			intPage = 1;
	}
	intRowCount = usi.getAllUser().size();//获得总记录数
	//记录总页数
	intPageCount = (intRowCount+intPageSize-1)/intPageSize;
	if(intPage>intPageCount)
		intPage = intPageCount;
%>
  <br><br><h2 align="center">选课系统用户管理列表</h2>
	<table border="0" cellpadding="0" cellspacing="2" align="center" width="600">
		<tr  height="20" bgcolor="#cccccc">
			<td width="200" align="center">编号</td>
			<td width="200" align="center">用户名</td>
			<td width="200" align="center">模式</td>
			<td width="200" align="center">工/学号</td>
		</tr>
		<%
		int num = 0;
		int number = 0;
		num = (intPage-1)*10;
		if(usi.getAllUser().size()-num<10)
			number = usi.getAllUser().size();
		else
			number = (intPage-1)*10+10;
			
		//从数据库中取出数据	
		for(int k=num;k<number;k++){
			user = (User)usi.getAllUser().get(k);
		%>
		<tr height="40">
			<td><%=user.getId() %></td>
			<td><%=user.getUser() %></td>
			<td><%=user.getRole() %></td>
			<td><%=user.getNo() %></td>
		</tr>	
		<%
		}
		%>	
	</table>
	<hr>
	<div align="center"> 
		<%		
		if(intPage>1){
		%>
		<a href="Manager/userlist.jsp?page=<%=intPage-1 %>">上一页</a>
		<%		
		}
		%>		
		&nbsp;&nbsp;当前页码为:第<%=intPage %>页&nbsp;&nbsp;/&nbsp;&nbsp;总共<%=intPageCount %>页&nbsp;&nbsp;&nbsp;
		<%
		if(intPage<intPageCount){
		%>
		<a href="Manager/userlist.jsp?page=<%=intPage+1 %>">下一页</a>
		<%
		}
		%>

	</div>
  </body>
</html>

 

你可能感兴趣的:(DAO,html,jsp,cache,css)