81,122
社区成员




<html>
<head>
<title>分页程序</title>
</head>
<body>
<center>
<h1>分页程序</h1>
<hr/>
<h2><a href="PersonServlet?queryWithKey=Y">进入MVC分页程序</a></h2>
</center>
</body>
</html>
<%@ page contentType="text/html;charset=utf-8" %>
<%@ page import="java.util.*" %>
<html>
<head>
<title>分页显示</title>
</head>
<body>
<center>
<h1>人员列表</h1>
<hr/>
<br/>
<%
request.setCharacterEncoding("utf-8"); //处理字符乱码
%>
<%
final String jspUrl = "list_person_sp.jsp"; //jsp页面地址
%>
<%
List allInfoDataList = request.getAttribute("allInfoDataList");
%>
<jsp:include page="list_person_inner.jsp" >
<jsp:param name="jspUrls" value="<%=jspUrl %>"/>
<jsp:param name="keyWords" value="<%=request.getAttribute("keyWord") %>"/>
<jsp:param name="lineSizes" value="<%=request.getAttribute("lineSize") %>"/>
<jsp:param name="currentPages" value="<%=request.getAttribute("currentPage") %>"/>
<jsp:param name="pageSizes" value="<%=request.getAttribute("pageSize") %>"/>
<jsp:param name="infoSizes" value="<%=request.getAttribute("infoSize") %>"/>
<jsp:param name="queryWithKeys" value="<%=request.getAttribute("queryWithKey")%>"/>
</jsp:include>
<table border="1" width="80%">
<tr>
<td>编号</td>
<td>名称</td>
<td>姓名</td>
<td>密码</td>
<td colspan="2">操作</td>
</tr>
<%
Iterator iter = allInfoDataList.iterator();
while(iter.hasNext()) {
pageContext.setAttribute("person",iter.next());
%>
<tr>
<td>${person.id}%></td>
<td>${person.uid}</td>
<td>${person.name}</td>
<td>${person.password}</td>
<td>更新</td>
<td>删除</td>
</tr>
<%
if(allInfoDataList.size() == 0) {
%>
<tr>
<td colspan="6">没有任何数据!!!</td>
</tr>
<%
}
%>
</table>
</center>
</body>
</html>
<%@ page contentType="text/html;charset=utf-8" %>
<script language="javaScript">
function openPage(curpage) {
document.spage.cp.value = curpage;
document.spage.submit();
}
function selToPage() {
document.spage.cp.value = document.spage.selpage.value;
document.spage.submit();
}
</script>
<%
request.setCharacterEncoding("utf-8"); //处理字符乱码
String keyWord = null; //接受关键字
%>
<%
String jspUrl = null; //jsp页面地址
//定义分页变量
int lineSize = 2; //每页要显示的记录数
int currentPage = 2; //当前第几页
int pageSize = 5; //总共多少页
int infoSize = 20; //总共的数据条数
String queryWithKey= "N";
%>
<%
try {
keyWord = request.getParameter("keyWords");
jspUrl = request.getParameter("jspUrls");
lineSize = Integer.parseInt(request.getParameter("lineSizes"));
currentPage = Integer.parseInt(request.getParameter("currentPages"));
pageSize = Integer.parseInt(request.getParameter("pageSizes"));
infoSize= Integer.parseInt(request.getParameter("infoSizes"));
} catch(Exception e) {
}
%>
<form name="spage" action="<%=jspUrl%>" method="post">
<%
if("Y".equals(request.getParameter("queryWithKey"))) {
%>
输入查询关键字:<input type="text" name="kw" value="<%=keyWord.equals("null")?"":keyWord%>" />
<input type="submit" value="查询" /><br/>
<%
}
%>
<%
if(infoSize != 0) {
%>
<input type="button" value="首页" onclick="openPage(1)" <%=currentPage == 1? "disabled" :"" %> />
<%-- ${pageList.first ? "disabled='disabled'" : "" --%>
<input type="button" value="上一页" onclick="openPage(<%=currentPage-1%>)" <%=currentPage == 1? "disabled" :"" %>/>
<input type="button" value="下一页" onclick="openPage(<%=currentPage+1%>)" <%=currentPage == pageSize? "disabled" :"" %>/>
<input type="button" value="尾页" onclick="openPage(<%=pageSize%>)" <%=currentPage == pageSize? "disabled" :"" %> />
<input type="hidden" name="cp" value="" />
<font color="red">共有<%=infoSize%>条数据 当前第<%=currentPage%></font>/<font color="red"><%=pageSize%>页</font>
去第
<select name="selpage" onChange="selToPage()">
<%
for(int i = 1; i <= pageSize; i++) {
%>
<option value="<%=i%>" <%=currentPage == i ? "selected" : ""%>><%=i%></option>
<%
}
%>
页
<%
}
%>
</form>
<%@ page contentType="text/html;charset=utf-8" %>
<%@ page import="java.util.*" %>
<html>
<head>
<title>分页显示</title>
</head>
<body>
<center>
<h1>人员列表</h1>
<hr/>
<br/>
<%
request.setCharacterEncoding("utf-8"); //处理字符乱码
%>
<%
final String jspUrl = "list_person_sp.jsp"; //jsp页面地址
%>
<%
List allInfoDataList = request.getAttribute("allInfoDataList");
%>
<jsp:include page="list_person_inner.jsp" >
<jsp:param name="jspUrls" value="<%=jspUrl %>"/>
<jsp:param name="keyWords" value="<%=request.getAttribute("keyWord") %>"/>
<jsp:param name="lineSizes" value="<%=request.getAttribute("lineSize") %>"/>
<jsp:param name="currentPages" value="<%=request.getAttribute("currentPage") %>"/>
<jsp:param name="pageSizes" value="<%=request.getAttribute("pageSize") %>"/>
<jsp:param name="infoSizes" value="<%=request.getAttribute("infoSize") %>"/>
<jsp:param name="queryWithKeys" value="<%=request.getAttribute("queryWithKey")%>"/>
</jsp:include>
<table border="1" width="80%">
<tr>
<td>编号</td>
<td>名称</td>
<td>姓名</td>
<td>密码</td>
<td colspan="2">操作</td>
</tr>
<%
Iterator iter = allInfoDataList.iterator();
while(iter.hasNext()) {
pageContext.setAttribute("person",iter.next());
%>
<tr>
<td>${person.id}%></td>
<td>${person.uid}</td>
<td>${person.name}</td>
<td>${person.password}</td>
<td>更新</td>
<td>删除</td>
</tr>
<%
if(allInfoDataList.size() == 0) {
%>
<tr>
<td colspan="6">没有任何数据!!!</td>
</tr>
<%
}
%>
</table>
</center>
</body>
</html>
Iterator iter = allInfoDataList.iterator();
while(iter.hasNext()) {
pageContext.setAttribute("person",iter.next());
}
-- 删除表
drop table person;
-- 创建person表
create table person (
-- 生成一个流水号,观察显示的记录数
id int auto_increment not null primary key,
-- 用户登录id
uid varchar(32),
-- 用户真实姓名
name varchar(32),
-- 用户的登录密码
password varchar(20)
);
insert into person(uid,name,password) values('zxy01','任逍遥01','zxiaoyao01');
insert into person(uid,name,password) values('zxy02','任逍遥02','zxiaoyao02');
insert into person(uid,name,password) values('zxy03','任逍遥03','zxiaoyao03');
insert into person(uid,name,password) values('zxy04','任逍遥04','zxiaoyao04');
insert into person(uid,name,password) values('zxy05','任逍遥05','zxiaoyao05');
insert into person(uid,name,password) values('zxy06','任逍遥06','zxiaoyao06');
insert into person(uid,name,password) values('zxy07','任逍遥07','zxiaoyao07');
insert into person(uid,name,password) values('zxy08','任逍遥08','zxiaoyao08');
insert into person(uid,name,password) values('zxy09','任逍遥09','zxiaoyao09');
insert into person(uid,name,password) values('zxy10','任逍遥10','zxiaoyao10');
insert into person(uid,name,password) values('zxy11','任逍遥11','zxiaoyao11');
insert into person(uid,name,password) values('zxy12','任逍遥12','zxiaoyao12');
insert into person(uid,name,password) values('zxy13','任逍遥13','zxiaoyao13');
insert into person(uid,name,password) values('zxy14','任逍遥14','zxiaoyao14');
insert into person(uid,name,password) values('zxy15','任逍遥15','zxiaoyao15');
insert into person(uid,name,password) values('zxy16','任逍遥16','zxiaoyao16');
insert into person(uid,name,password) values('zxy17','任逍遥17','zxiaoyao17');
insert into person(uid,name,password) values('zxy18','任逍遥18','zxiaoyao18');
insert into person(uid,name,password) values('zxy19','任逍遥19','zxiaoyao19');
insert into person(uid,name,password) values('zxy20','任逍遥20','zxiaoyao20');
insert into person(uid,name,password) values('zxy21','任逍遥21','zxiaoyao21');
insert into person(uid,name,password) values('zxy22','任逍遥22','zxiaoyao22');
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd"
version="2.4">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<!-- MVC-DAO 例子的servlet -->
<servlet>
<servlet-name>person</servlet-name>
<servlet-class>com.zxiaoyao.mvcdao.servlet.PersonServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>person</servlet-name>
<url-pattern>/struts/mvcdao/PersonServlet</url-pattern>
</servlet-mapping>
</web-app>